| /******************/ | /******************/ | ||||
| function initialize() { | function initialize() { | ||||
| chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| let shouldKillSticky = checkForShouldKillSticky(result); | let shouldKillSticky = checkForShouldKillSticky(result); | ||||
| updateIcon(shouldKillSticky); | updateIcon(shouldKillSticky); | ||||
| if (shouldKillSticky) { | if (shouldKillSticky) { |
| let matchingPatterns = document.querySelector("#matchingPatterns textarea").value; | let matchingPatterns = document.querySelector("#matchingPatterns textarea").value; | ||||
| let exclusionPatterns = document.querySelector("#exclusionPatterns textarea").value; | let exclusionPatterns = document.querySelector("#exclusionPatterns textarea").value; | ||||
| let mode = document.querySelector("input#whitelist-mode").checked ? "whitelist" : "blacklist"; | let mode = document.querySelector("input#whitelist-mode").checked ? "whitelist" : "blacklist"; | ||||
| chrome.storage.sync.set({ | |||||
| chrome.storage.local.set({ | |||||
| "matchingPatterns": matchingPatterns, | "matchingPatterns": matchingPatterns, | ||||
| "exclusionPatterns": exclusionPatterns, | "exclusionPatterns": exclusionPatterns, | ||||
| "mode": mode | "mode": mode | ||||
| }, () => { setButtonsActive(false); }); | |||||
| }, () => { | |||||
| let error = chrome.runtime.lastError; | |||||
| if (error) { | |||||
| alert(error.message); | |||||
| } else { | |||||
| setButtonsActive(false); | |||||
| } | |||||
| }); | |||||
| } | } | ||||
| /* Retrieves the saved state from storage and reset the UI to reflect it, | /* Retrieves the saved state from storage and reset the UI to reflect it, | ||||
| discarding the user's changes. | discarding the user's changes. | ||||
| */ | */ | ||||
| function resetChanges(callback) { | function resetChanges(callback) { | ||||
| chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| AKS.matchingPatterns = result.matchingPatterns || ""; | AKS.matchingPatterns = result.matchingPatterns || ""; | ||||
| AKS.exclusionPatterns = result.exclusionPatterns || "" | AKS.exclusionPatterns = result.exclusionPatterns || "" | ||||
| AKS.mode = result.mode || "blacklist"; | AKS.mode = result.mode || "blacklist"; |
| { | { | ||||
| "manifest_version": 2, | "manifest_version": 2, | ||||
| "name": "AlwaysKillSticky", | "name": "AlwaysKillSticky", | ||||
| "version": "1.2.5.2", | |||||
| "version": "1.2.6", | |||||
| "description": "Get rid of sticky elements on websites - permanently!", | "description": "Get rid of sticky elements on websites - permanently!", | ||||
| "author": "Said Achmiz", | "author": "Said Achmiz", | ||||
| "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", | "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", | ||||
| "permissions": [ "activeTab", "storage" ], | |||||
| "permissions": [ "activeTab", "storage", "unlimitedStorage" ], | |||||
| "background": { | "background": { | ||||
| "scripts": ["background.js"], | "scripts": ["background.js"], | ||||
| "persistent": false | "persistent": false |
| { | { | ||||
| "manifest_version": 2, | "manifest_version": 2, | ||||
| "name": "AlwaysKillSticky", | "name": "AlwaysKillSticky", | ||||
| "version": "1.2.5.2", | |||||
| "version": "1.2.6", | |||||
| "description": "Get rid of sticky elements on websites - permanently!", | "description": "Get rid of sticky elements on websites - permanently!", | ||||
| "author": "Said Achmiz", | "author": "Said Achmiz", | ||||
| "browser_specific_settings": { | "browser_specific_settings": { | ||||
| } | } | ||||
| }, | }, | ||||
| "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", | "homepage_url": "https://git.sr.ht/~achmizs/AlwaysKillSticky.git", | ||||
| "permissions": [ "activeTab", "storage" ], | |||||
| "permissions": [ "activeTab", "storage", "unlimitedStorage" ], | |||||
| "background": { | "background": { | ||||
| "scripts": [ "background.js" ] | "scripts": [ "background.js" ] | ||||
| }, | }, |
| chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { | chrome.tabs.query({currentWindow: true, active: true}, (tabs) => { | ||||
| AKS.activeTabLocation = tabs[0].url; | AKS.activeTabLocation = tabs[0].url; | ||||
| AKS.activeTabID = tabs[0].id; | AKS.activeTabID = tabs[0].id; | ||||
| chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| chrome.storage.local.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => { | |||||
| updateState(result); | updateState(result); | ||||
| updateUIState(); | updateUIState(); | ||||
| }); | }); | ||||
| // Listener for main button. | // Listener for main button. | ||||
| document.querySelector("button.main-button").addActivateEvent((event) => { | document.querySelector("button.main-button").addActivateEvent((event) => { | ||||
| /* This doesn’t actually kill the stickies yet; that’s below, in the | /* This doesn’t actually kill the stickies yet; that’s below, in the | ||||
| callback to storage.sync.set. */ | |||||
| callback to storage.local.set. */ | |||||
| toggleState(); | toggleState(); | ||||
| // Prepare the changes for saving. | // Prepare the changes for saving. | ||||
| changes.matchingPatterns = AKS.matchingPatterns.join("\n"); | changes.matchingPatterns = AKS.matchingPatterns.join("\n"); | ||||
| // Save the changes. | // Save the changes. | ||||
| chrome.storage.sync.set(changes, () => { | |||||
| chrome.storage.local.set(changes, () => { | |||||
| let error = chrome.runtime.lastError; | |||||
| if (error) { | |||||
| alert(error.message); | |||||
| return; | |||||
| } | |||||
| // Update the UI, once changes are saved. | // Update the UI, once changes are saved. | ||||
| updateUIState(); | updateUIState(); | ||||
| let reloadButton = document.querySelector("button.reload-button"); | let reloadButton = document.querySelector("button.reload-button"); |