2021-04-08 21:50:24 +00:00
|
|
|
/**
|
|
|
|
* @constant chromeUrl
|
|
|
|
* @description Chrome Web Store link
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const chromeUrl =
|
|
|
|
"https://chrome.google.com/webstore/detail/do-not-consent/djcbfpkdhdkaflcigibkbpboflaplabg";
|
|
|
|
|
2021-06-27 11:16:38 +00:00
|
|
|
/**
|
|
|
|
* @constant dispatch
|
|
|
|
* @description Shortcut to send messages to background script
|
|
|
|
* @type {void}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const dispatch = chrome.runtime.sendMessage;
|
|
|
|
|
2021-04-08 21:50:24 +00:00
|
|
|
/**
|
|
|
|
* @constant firefoxUrl
|
|
|
|
* @description Firefox Add-ons link
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const firefoxUrl =
|
|
|
|
"https://addons.mozilla.org/es/firefox/addon/do-not-consent/";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant isChromium
|
|
|
|
* @description Is current browser an instance of Chromium?
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
|
|
|
|
const isChromium = chrome.runtime.getURL("").startsWith("chrome-extension://");
|
|
|
|
|
|
|
|
/**
|
2021-04-11 09:44:12 +00:00
|
|
|
* @function handlePowerChange
|
|
|
|
* @description Disables or enables extension on current page
|
2021-04-08 21:50:24 +00:00
|
|
|
*/
|
|
|
|
|
2021-06-27 11:16:38 +00:00
|
|
|
const handlePowerChange = () => {
|
|
|
|
dispatch({ type: "GET_TAB" }, null, ({ hostname, id }) => {
|
|
|
|
dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => {
|
|
|
|
const power = document.getElementById("power");
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
hostname,
|
|
|
|
state: { enabled: !enabled },
|
|
|
|
type: "UPDATE_CACHE",
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: !enabled === true ? "ENABLE_ICON" : "DISABLE_ICON",
|
|
|
|
});
|
|
|
|
if (!enabled === false) power.removeAttribute("checked");
|
|
|
|
if (!enabled === true) power.setAttribute("checked", "checked");
|
|
|
|
chrome.tabs.reload(id, { bypassCache: true });
|
|
|
|
});
|
2021-06-23 11:26:29 +00:00
|
|
|
});
|
2021-04-08 21:50:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-04-11 09:44:12 +00:00
|
|
|
* @function handleReload
|
|
|
|
* @description Reload current page
|
|
|
|
*/
|
|
|
|
|
2021-06-27 11:16:38 +00:00
|
|
|
const handleReload = () => {
|
|
|
|
dispatch({ type: "GET_TAB" }, null, ({ id }) => {
|
2021-06-23 11:26:29 +00:00
|
|
|
chrome.tabs.reload(id, { bypassCache: true });
|
|
|
|
});
|
2021-04-11 09:44:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function handleRate
|
|
|
|
* @description Shows negative or positive messages
|
2021-04-08 21:50:24 +00:00
|
|
|
*
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
|
|
|
|
2021-04-11 09:44:12 +00:00
|
|
|
const handleRate = (event) => {
|
2021-04-08 21:50:24 +00:00
|
|
|
const negative = document.getElementById("negative");
|
|
|
|
const positive = document.getElementById("positive");
|
2021-04-11 09:44:12 +00:00
|
|
|
|
|
|
|
switch (event.currentTarget.id) {
|
|
|
|
case "unlike":
|
|
|
|
positive.setAttribute("hidden", "true");
|
2021-04-08 21:50:24 +00:00
|
|
|
negative.removeAttribute("hidden");
|
|
|
|
break;
|
2021-04-11 09:44:12 +00:00
|
|
|
case "like":
|
|
|
|
negative.setAttribute("hidden", "true");
|
2021-04-08 21:50:24 +00:00
|
|
|
positive.removeAttribute("hidden");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @function handleContentLoaded
|
|
|
|
* @description Setup stars handlers and result message links
|
|
|
|
*/
|
|
|
|
|
2021-06-27 11:16:38 +00:00
|
|
|
const handleContentLoaded = () => {
|
|
|
|
dispatch({ type: "GET_TAB" }, null, ({ hostname, id }) => {
|
|
|
|
dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => {
|
|
|
|
const host = document.getElementById("host");
|
|
|
|
const like = document.getElementById("like");
|
|
|
|
const power = document.getElementById("power");
|
|
|
|
const reload = document.getElementById("reload");
|
|
|
|
const store = document.getElementById("store");
|
|
|
|
const unlike = document.getElementById("unlike");
|
|
|
|
|
|
|
|
like.addEventListener("click", handleRate);
|
|
|
|
power.addEventListener("change", handlePowerChange);
|
|
|
|
reload.addEventListener("click", handleReload);
|
|
|
|
store.setAttribute("href", isChromium ? chromeUrl : firefoxUrl);
|
|
|
|
unlike.addEventListener("click", handleRate);
|
|
|
|
if (location) host.innerText = hostname.replace("www.", "");
|
|
|
|
if (!enabled) power.removeAttribute("checked");
|
|
|
|
});
|
2021-06-23 11:26:29 +00:00
|
|
|
});
|
2021-04-08 21:50:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description Listen to document ready
|
|
|
|
*
|
|
|
|
* @type {Document}
|
|
|
|
* @listens document#ready
|
|
|
|
*/
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", handleContentLoaded);
|