diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md deleted file mode 100644 index b54589e..0000000 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: bug report -about: experienced any broken/glitchy enhancer behaviour? -title: '' -labels: bug -assignees: '' ---- - -FILL OUT THIS TEMPLATE, REMOVING/REPLACING ALL NON-BOLD TEXT WITH YOUR OWN INFORMATION. -BE AS CLEAR AND CONCISE AS POSSIBLE. - -**describe the bug** -what is the bug - what happens? - -**expected behaviour** -why is this a bug - what should be happening? - -**screenshots** -if applicable, add screenshots of your problem. - -**platform** -what OS are you using? e.g. windows 7, windows 10, WSL, ubuntu, arch linux, macOS diff --git a/.github/ISSUE_TEMPLATE/feature-proposal.md b/.github/ISSUE_TEMPLATE/feature-proposal.md deleted file mode 100644 index 9f339d4..0000000 --- a/.github/ISSUE_TEMPLATE/feature-proposal.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -name: feature proposal -about: got an idea/request/suggestion for a new feature/module? -title: '' -labels: enhancement -assignees: '' ---- - -FILL OUT THIS TEMPLATE, REMOVING/REPLACING ALL NON-BOLD TEXT WITH YOUR OWN INFORMATION. -BE AS CLEAR AND CONCISE AS POSSIBLE. - -ONCE ALL INFORMATION HERE HAS BEEN FILLED IN, THE MODULE WILL BE REVIEWED & DISCUSSED -BY OTHER CONTRIBUTORS AND BY THE COMMUNITY. IF IT IS APPROVED AS SOMETHING USEFUL/BENEFICIAL, -THEN IT IS GUARANTEED TO BE ADDED TO THE ENHANCER. - -IF YOU WOULD LIKE TO CONTRIBUTE AND CODE THIS YOURSELF, THAT'D BE AWESOME! JUST OPEN A -PULL REQUEST WHEN YOU'RE READY. IF PROGRAMMING ISN'T YOUR THING, ANOTHER DEV WILL COME -ALONG AND PICK THE IDEA UP. - -ONCE SOMEONE STARTS WORK ON THIS, THE ISSUE WILL BE ASSIGNED TO THEIR GITHUB ACCOUNT -SO MULTIPLE PEOPLE DON'T ALL WORK ON THE SAME THING: IF YOU PLAN ON MAKING THIS, SAY SO! - -**problem** - -why is this feature necessary? how will it help? what existing shortcomings does it address? - -**solution** - -how will this feature appear/act? - -how could this be technically implemented using the available -capabilities of the enhancer and notion? - -**cons** - -what are the potential costs or dangers of this feature, or things that may go -outside of the enhancer's scope? e.g. bad performance, security issues, or -modifying the data notion stores. - -**alternatives** - -would a different feature remove the need for this? - -does this need to be implemented by the enhancer? could an external service work better? -e.g. playing background music via noisli or youtube. diff --git a/.github/workflows/potential-duplicates.yml b/.github/workflows/potential-duplicates.yml deleted file mode 100644 index dce768d..0000000 --- a/.github/workflows/potential-duplicates.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: potential duplicates -on: - issues: - types: [opened, edited] -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: bubkoo/potential-duplicates@v1 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Label to set, when potential duplicates are detected. - label: potential-duplicate - # Get issues with state to compare. Supported state: 'all', 'closed', 'open'. - state: all - # If similarity is higher than this threshold([0,1]), issue will be marked as duplicate. - threshold: 0.6 - # Reactions to be add to comment when potential duplicates are detected. - # Available reactions: "-1", "+1", "confused", "laugh", "heart", "hooray", "rocket", "eyes" - reactions: 'confused' - # Comment to post when potential duplicates are detected. - comment: > - potential duplicates: - {{#issues}} - - [#{{ number }}] {{ title }} ({{ accuracy }}%) - {{/issues}} diff --git a/.github/workflows/submodules.yml b/.github/workflows/submodules.yml new file mode 100644 index 0000000..463aa5e --- /dev/null +++ b/.github/workflows/submodules.yml @@ -0,0 +1,20 @@ +name: 'update submodules' + +on: + workflow_dispatch: + +jobs: + sync: + name: 'update submodules' + runs-on: ubuntu-latest + steps: + - name: checkout repo + uses: actions/checkout@v2 + with: + submodules: true + - name: pull updates + run: | + git pull --recurse-submodules + git submodule update --remote --recursive + - name: commit changes + uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d1db488 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,16 @@ +[submodule "api"] + path = insert/api + url = git@github.com:notion-enhancer/api.git + branch = dev +[submodule "repo"] + path = insert/repo + url = git@github.com:notion-enhancer/repo.git + branch = dev +[submodule "media"] + path = insert/media + url = git@github.com:notion-enhancer/media.git + branch = main +[submodule "dep"] + path = insert/dep + url = git@github.com:notion-enhancer/dep.git + branch = main diff --git a/insert/api b/insert/api new file mode 160000 index 0000000..aff6f2d --- /dev/null +++ b/insert/api @@ -0,0 +1 @@ +Subproject commit aff6f2dafa9d2666306f4e088da86528aeee0cd8 diff --git a/insert/dep b/insert/dep new file mode 160000 index 0000000..9a3893f --- /dev/null +++ b/insert/dep @@ -0,0 +1 @@ +Subproject commit 9a3893fbd5af4d02b89ea4c6f2b35971a3a91408 diff --git a/insert/env/env.mjs b/insert/env/env.mjs new file mode 100644 index 0000000..705c578 --- /dev/null +++ b/insert/env/env.mjs @@ -0,0 +1,44 @@ +/* + * notion-enhancer core: api + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +/** + * environment-specific methods and constants + * @module notion-enhancer/api/env + */ + +/** + * the environment/platform name code is currently being executed in + * @constant + * @type {string} + */ +export const name = process.platform; + +/** + * the current version of the enhancer + * @constant + * @type {string} + */ +export const version = chrome.runtime.getManifest().version; + +/** + * open the enhancer's menu + * @type {function} + */ +export const focusMenu = () => chrome.runtime.sendMessage({ action: 'focusMenu' }); + +/** + * focus an active notion tab + * @type {function} + */ +export const focusNotion = () => chrome.runtime.sendMessage({ action: 'focusNotion' }); + +/** + * reload all notion and enhancer menu tabs to apply changes + * @type {function} + */ +export const reload = () => chrome.runtime.sendMessage({ action: 'reload' }); diff --git a/insert/env/fs.mjs b/insert/env/fs.mjs new file mode 100644 index 0000000..376440f --- /dev/null +++ b/insert/env/fs.mjs @@ -0,0 +1,51 @@ +/* + * notion-enhancer core: api + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +/** + * environment-specific filesystem reading + * @module notion-enhancer/api/fs + */ + +/** + * transform a path relative to the enhancer root directory into an absolute path + * @param {string} path - a url or within-the-enhancer filepath + * @returns {string} an absolute filepath + */ +export const localPath = chrome.runtime.getURL; + +/** + * fetch and parse a json file's contents + * @param {string} path - a url or within-the-enhancer filepath + * @param {object} [opts] - the second argument of a fetch() request + * @returns {object} the json value of the requested file as a js object + */ +export const getJSON = (path, opts = {}) => + fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.json()); + +/** + * fetch a text file's contents + * @param {string} path - a url or within-the-enhancer filepath + * @param {object} [opts] - the second argument of a fetch() request + * @returns {string} the text content of the requested file + */ +export const getText = (path, opts = {}) => + fetch(path.startsWith('http') ? path : localPath(path), opts).then((res) => res.text()); + +/** + * check if a file exists + * @param {string} path - a url or within-the-enhancer filepath + * @returns {boolean} whether or not the file exists + */ +export const isFile = async (path) => { + try { + await fetch(path.startsWith('http') ? path : localPath(path)); + return true; + } catch { + return false; + } +}; diff --git a/insert/env/storage.mjs b/insert/env/storage.mjs new file mode 100644 index 0000000..3003231 --- /dev/null +++ b/insert/env/storage.mjs @@ -0,0 +1,121 @@ +/* + * notion-enhancer core: api + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +/** + * environment-specific data persistence + * @module notion-enhancer/api/storage + */ + +const _queue = [], + _onChangeListeners = []; + +/** + * get persisted data + * @param {array} path - the path of keys to the value being fetched + * @param {*} [fallback] - a default value if the path is not matched + * @returns {Promise} value ?? fallback + */ +export const get = (path, fallback = undefined) => { + if (!path.length) return fallback; + return new Promise((res, rej) => + chrome.storage.local.get(async (values) => { + let value = values; + while (path.length) { + if (value === undefined) { + value = fallback; + break; + } + value = value[path.shift()]; + } + res(value ?? fallback); + }) + ); +}; + +/** + * persist data + * @param {array} path - the path of keys to the value being set + * @param {*} value - the data to save + * @returns {Promise} resolves when data has been saved + */ +export const set = (path, value) => { + if (!path.length) return undefined; + const precursor = _queue[_queue.length - 1] || undefined, + interaction = new Promise(async (res, rej) => { + if (precursor !== undefined) { + await precursor; + _queue.shift(); + } + const pathClone = [...path], + namespace = path[0]; + chrome.storage.local.get(async (values) => { + let pointer = values, + old; + while (path.length) { + const key = path.shift(); + if (!path.length) { + old = pointer[key]; + pointer[key] = value; + break; + } + pointer[key] = pointer[key] ?? {}; + pointer = pointer[key]; + } + chrome.storage.local.set({ [namespace]: values[namespace] }, () => { + _onChangeListeners.forEach((listener) => + listener({ type: 'set', path: pathClone, new: value, old }) + ); + res(value); + }); + }); + }); + _queue.push(interaction); + return interaction; +}; + +/** + * create a wrapper for accessing a partition of the storage + * @param {array} namespace - the path of keys to prefix all storage requests with + * @param {function} [get] - the storage get function to be wrapped + * @param {function} [set] - the storage set function to be wrapped + * @returns {object} an object with the wrapped get/set functions + */ +export const db = (namespace, getFunc = get, setFunc = set) => { + if (typeof namespace === 'string') namespace = [namespace]; + return { + get: (path = [], fallback = undefined) => getFunc([...namespace, ...path], fallback), + set: (path, value) => setFunc([...namespace, ...path], value), + }; +}; + +/** + * add an event listener for changes in storage + * @param {onStorageChangeCallback} callback - called whenever a change in + * storage is initiated from the current process + */ +export const addChangeListener = (callback) => { + _onChangeListeners.push(callback); +}; + +/** + * remove a listener added with storage.addChangeListener + * @param {onStorageChangeCallback} callback + */ +export const removeChangeListener = (callback) => { + _onChangeListeners = _onChangeListeners.filter((listener) => listener !== callback); +}; + +/** + * @callback onStorageChangeCallback + * @param {object} event + * @param {string} event.type - 'set' or 'reset' + * @param {string} event.namespace- the name of the store, e.g. a mod id + * @param {string} [event.key] - the key associated with the changed value + * @param {string} [event.new] - the new value being persisted to the store + * @param {string} [event.old] - the previous value associated with the key + */ diff --git a/insert/media b/insert/media new file mode 160000 index 0000000..0e56fb9 --- /dev/null +++ b/insert/media @@ -0,0 +1 @@ +Subproject commit 0e56fb9242a00e41132b9ad30adef9ae910a2159 diff --git a/insert/repo b/insert/repo new file mode 160000 index 0000000..4c589ec --- /dev/null +++ b/insert/repo @@ -0,0 +1 @@ +Subproject commit 4c589ec5915cccfb004098caf08e8934eb73ade7 diff --git a/pkg/replacers/main/main.mjs b/pkg/replacers/main/main.mjs index ae80308..f8b6fe6 100644 --- a/pkg/replacers/main/main.mjs +++ b/pkg/replacers/main/main.mjs @@ -1,7 +1,7 @@ /* * notion-enhancer - * (c) 2020 dragonwocky (https://dragonwocky.me/) - * (https://dragonwocky.me/notion-enhancer) under the MIT license + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license */ 'use strict';