Removing Object.prototype functions

Improve compatibility across browsers + not a best practice
pull/512/head^2
Kevin Payravi 2024-02-27 02:55:41 -06:00
parent 1d68c9d1a8
commit a66f3c91a8
4 changed files with 15 additions and 51 deletions

View File

@ -150,15 +150,6 @@ function redirectToBreezeWiki(storage, tabId, url) {
}
async function main(url, tabId) {
// Create object prototypes for getting and setting attributes
Object.prototype.get = function (prop) {
this[prop] = this[prop] || {};
return this[prop];
};
Object.prototype.set = function (prop, value) {
this[prop] = value;
}
chrome.storage.local.get((localStorage) => {
chrome.storage.sync.get(async (syncStorage) => {
const storage = { ...syncStorage, ...localStorage };

View File

@ -1,14 +1,5 @@
var sites = [];
// Create object prototypes for getting and setting attributes:
Object.prototype.get = function (prop) {
this[prop] = this[prop] || {};
return this[prop];
};
Object.prototype.set = function (prop, value) {
this[prop] = value;
}
// Clear wiki toggles
// Used when switching languages
function resetOptions() {
@ -192,7 +183,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings.set(key, 'disabled');
wikiSettings[key] = 'disabled';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
@ -200,7 +191,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings.set(key, 'alert');
wikiSettings[key] = 'alert';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
@ -208,7 +199,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
var key = input.target.getAttribute('data-wiki-key');
wikiSettings.set(key, 'redirect');
wikiSettings[key] = 'redirect';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
});
@ -216,7 +207,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings.set(key, 'disabled');
searchEngineSettings[key] = 'disabled';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
@ -224,7 +215,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings.set(key, 'replace');
searchEngineSettings[key] = 'replace';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
@ -232,7 +223,7 @@ async function loadOptions(lang, textFilter = '') {
chrome.storage.sync.get({ 'searchEngineSettings': {} }, async (response) => {
let searchEngineSettings = await commonFunctionDecompressJSON(response.searchEngineSettings);
var key = input.target.getAttribute('data-wiki-key');
searchEngineSettings.set(key, 'hide');
searchEngineSettings[key] = 'hide';
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
});
@ -325,7 +316,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleRedirect');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'redirect');
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'redirect';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
@ -335,7 +326,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleAlert');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'alert');
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'alert';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
@ -345,7 +336,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleDisable');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
wikiSettings.set(toggles[i].getAttribute('data-wiki-key'), 'disabled');
wikiSettings[toggles[i].getAttribute('data-wiki-key')] = 'disabled';
}
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
});
@ -355,7 +346,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineDisabled');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'disabled');
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'disabled';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
@ -365,7 +356,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineHide');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'hide');
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'hide';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});
@ -375,7 +366,7 @@ async function loadOptions(lang, textFilter = '') {
const toggles = document.querySelectorAll('#toggles input.toggleSearchEngineReplace');
for (var i = 0; i < toggles.length; i++) {
toggles[i].checked = true;
searchEngineSettings.set(toggles[i].getAttribute('data-wiki-key'), 'replace');
searchEngineSettings[toggles[i].getAttribute('data-wiki-key')] = 'replace';
}
chrome.storage.sync.set({ 'searchEngineSettings': await commonFunctionCompressJSON(searchEngineSettings) });
});

View File

@ -1,15 +1,6 @@
const breezewikiRegex = /breezewiki\.com$|antifandom\.com$|bw\.artemislena\.eu$|breezewiki\.catsarch\.com$|breezewiki\.esmailelbob\.xyz$|breezewiki\.frontendfriendly\.xyz$|bw\.hamstro\.dev$|breeze\.hostux\.net$|breezewiki\.hyperreal\.coffee$|breeze\.mint\.lgbt$|breezewiki\.nadeko\.net$|nerd\.whatever\.social$|breeze\.nohost\.network$|z\.opnxng\.com$|bw\.projectsegfau\.lt$|breezewiki\.pussthecat\.org$|bw\.vern\.cc$|breeze\.whateveritworks\.org$|breezewiki\.woodland\.cafe$/;
const currentURL = new URL(document.location);
// Create object prototypes for getting and setting attributes:
Object.prototype.get = function (prop) {
this[prop] = this[prop] || {};
return this[prop];
};
Object.prototype.set = function (prop, value) {
this[prop] = value;
}
function outputCSS() {
if (!document.getElementById('iwb-banner-styles')) {
styleString = `
@ -209,7 +200,7 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerRestoreLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings.set(id, 'alert');
wikiSettings[id] = 'alert';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Banner restored';
e.target.classList.add('indie-wiki-banner-disabled');
@ -231,7 +222,7 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerDisableLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings.set(id, 'disabled');
wikiSettings[id] = 'disabled';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Banner disabled';
e.target.classList.add('indie-wiki-banner-disabled');
@ -251,7 +242,7 @@ function displayRedirectBanner(newUrl, id, destinationName, destinationLanguage,
bannerRedirectLink.onclick = function (e) {
chrome.storage.sync.get({ 'wikiSettings': {} }, async (response) => {
let wikiSettings = await commonFunctionDecompressJSON(response.wikiSettings);
wikiSettings.set(id, 'redirect');
wikiSettings[id] = 'redirect';
chrome.storage.sync.set({ 'wikiSettings': await commonFunctionCompressJSON(wikiSettings) });
e.target.textContent = '✓ Redirect enabled';
e.target.classList.add('indie-wiki-banner-disabled');

View File

@ -1,15 +1,6 @@
const currentURL = new URL(document.location);
let hiddenWikisRevealed = {};
// Create object prototypes for getting and setting attributes:
Object.prototype.get = function (prop) {
this[prop] = this[prop] || {};
return this[prop];
};
Object.prototype.set = function (prop, value) {
this[prop] = value;
}
function base64Decode(text) {
text = text.replace(/\s+/g, '').replace(/\-/g, '+').replace(/\_/g, '/');
return decodeURIComponent(Array.prototype.map.call(atob(text), function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join(''));