Merge pull request #342 from wanhose/v6.4.4

6.4.4
This commit is contained in:
wanhose 2023-11-08 09:38:33 +01:00 committed by GitHub
commit 15bf81ca12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Cookie Dialog Monster", "name": "Cookie Dialog Monster",
"version": "6.4.3", "version": "6.4.4",
"default_locale": "en", "default_locale": "en",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"icons": { "icons": {

View File

@ -46,12 +46,16 @@ const storage = chrome.storage.local;
*/ */
const refreshData = (callback) => { const refreshData = (callback) => {
try {
fetch(`${apiUrl}/data/`).then((result) => { fetch(`${apiUrl}/data/`).then((result) => {
result.json().then(({ data }) => { result.json().then(({ data }) => {
chrome.storage.local.set({ data }); chrome.storage.local.set({ data });
callback?.(data); callback?.(data);
}); });
}); });
} catch {
refreshData(callback);
}
}; };
/** /**

View File

@ -16,7 +16,7 @@ const dispatch = chrome.runtime.sendMessage;
* @type {string} * @type {string}
*/ */
const hostname = document.location.hostname.split('.').slice(-3).join('.').replace('www.', ''); const hostname = getHostname();
/** /**
* @description Options provided to observer * @description Options provided to observer
@ -80,6 +80,22 @@ function forceElementStyles(element) {
element.style.setProperty('display', 'none', 'important'); element.style.setProperty('display', 'none', 'important');
} }
/**
* @description Calculates current hostname
* @returns {string}
*/
function getHostname() {
let hostname = document.location.hostname;
const referrer = document.referrer;
if (referrer) {
hostname = new URL(referrer).hostname;
}
return hostname.split('.').slice(-3).join('.').replace('www.', '');
}
/** /**
* @description Checks if an element is visible in the viewport * @description Checks if an element is visible in the viewport
* @param {HTMLElement} element * @param {HTMLElement} element
@ -177,7 +193,7 @@ function fix() {
} }
} }
if (skips.some((x) => !hostname.match(x.replace(/\*/g, '[^ ]*')))) { if (skips.every((x) => !hostname.match(x.replace(/\*/g, '[^ ]*')))) {
for (const element of [document.body, document.documentElement]) { for (const element of [document.body, document.documentElement]) {
element?.classList.remove(...(data?.classes ?? [])); element?.classList.remove(...(data?.classes ?? []));
element?.style.setProperty('position', 'initial', 'important'); element?.style.setProperty('position', 'initial', 'important');
@ -280,7 +296,7 @@ window.addEventListener('pageshow', (event) => {
*/ */
window.addEventListener('run', () => { window.addEventListener('run', () => {
if (data?.elements.length && state.enabled && !preview) { if (data?.elements.length && document.body && state.enabled && !preview) {
if (readingTime() < 4) { if (readingTime() < 4) {
forceClean(document.body); forceClean(document.body);
} else { } else {