From 662c79e76171f4c4cf20fe2e42339e3b39168300 Mon Sep 17 00:00:00 2001 From: fuwaa Date: Thu, 21 Jul 2022 13:51:54 +0800 Subject: [PATCH] docs: add documentation --- src/methods/helper.js | 49 ++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/methods/helper.js b/src/methods/helper.js index 5a6a715..03f1aaf 100644 --- a/src/methods/helper.js +++ b/src/methods/helper.js @@ -1,5 +1,10 @@ /*global chrome*/ +/** + * Set a key and autoreload + * @param {string} setting - setting to update + * @param {string} value - Color to replace the current color with + */ export function pintSet(setting, value) { var pintKey = {}; pintKey[`${setting}`] = value; @@ -7,43 +12,35 @@ export function pintSet(setting, value) { chrome.tabs.reload(); } +/** + * Set a key without reloading + * @param {string} setting - setting to update + * @param {string} value - Color to replace the current color with + */ export function pintSetNoReload(setting, value) { var pintKey = {}; pintKey[`${setting}`] = value; chrome.storage.local.set(pintKey); } -export function pintGet(setting, cb) { - var output = ""; - chrome.storage.local.get([`${setting}`], function (result) { - output = result[`${setting}`]; - cb(output); - }); -} - +/** + * Gets a setting and calls it back (normally used for react useState) + * @param {string} setting - get this setting + * @param {string} func - Function to Callback + */ export function pintGetUpdate(setting, func) { chrome.storage.local.get([`${setting}`], function (result) { func(result[`${setting}`]); }); } -export function updateMultiple(array, color) { - for (var i = 0; i < array.length; i++) { - pintSetNoReload(array[i], color); +/** + * Updates multiple settings at once + * @param {array} settings - settings of settings to update + * @param {string} color - Color to replace the current color with + */ +export function updateMultiple(settings, color) { + for (var i = 0; i < settings.length; i++) { + pintSetNoReload(settings[i], color); } } -// export function pintGet(setting) { -// pintGetInner(setting, finalReturn); -// alert(`returned value: ${value}`); -// return value; -// } - -// export function (setting, callback) { -// callback(result[setting]); -// }); -// }; - -// function finalReturn(finalValue) { -// alert(`result is: ${finalValue}`); -// value = finalValue -// }