Przeglądaj źródła

Many bug fixes

master
Said Achmiz 6 lat temu
rodzic
commit
e82376a7ef
2 zmienionych plików z 24 dodań i 25 usunięć
  1. 6
    5
      contentScript.js
  2. 18
    20
      popup.js

+ 6
- 5
contentScript.js Wyświetl plik

@@ -11,19 +11,20 @@ function killStickyIfMatch(result) {
var shouldKillSticky = false;
let matchingPatterns = result.mode == "whitelist" ?
[ ".*" ] :
result.matchingPatterns.split("\n");
(typeof result.matchingPatterns != "undefined" ?
result.matchingPatterns.split("\n") :
[ ]);
for (let pattern of matchingPatterns) {
if (location.href.match(new RegExp(pattern))) {
if (pattern && location.href.match(new RegExp(pattern))) {
shouldKillSticky = true;
break;
}
}
let exclusionPatterns = (typeof result.exclusionPatterns != "undefined" &&
result.exclusionPatterns != "") ?
let exclusionPatterns = typeof result.exclusionPatterns != "undefined" ?
result.exclusionPatterns.split("\n") :
[ ];
for (let pattern of exclusionPatterns) {
if (location.href.match(new RegExp(pattern))) {
if (pattern && location.href.match(new RegExp(pattern))) {
shouldKillSticky = false;
break;
}

+ 18
- 20
popup.js Wyświetl plik

@@ -1,8 +1,3 @@
/*******************/
/* EVENT LISTENERS */
/*******************/


/***********/
/* HELPERS */
/***********/
@@ -74,13 +69,13 @@ function recalculatePatternEffects() {
ASK.pageMatched = false;
ASK.pageExcluded = false;
for (let pattern of ASK.matchingPatterns) {
if (ASK.activeTabLocation.match(new RegExp(pattern))) {
if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) {
ASK.pageMatched = true;
break;
}
}
for (let pattern of ASK.exclusionPatterns) {
if (ASK.activeTabLocation.match(new RegExp(pattern))) {
if (pattern && ASK.activeTabLocation.match(new RegExp(pattern))) {
ASK.pageExcluded = true;
break;
}
@@ -91,9 +86,10 @@ function updateState(result) {
ASK.mode = result.mode || "blacklist";
ASK.matchingPatterns = (ASK.mode == "whitelist") ?
[ ".*" ] :
result.matchingPatterns.split("\n");
ASK.exclusionPatterns = (typeof result.exclusionPatterns != "undefined" &&
result.exclusionPatterns != "") ?
(typeof result.matchingPatterns != "undefined" ?
result.matchingPatterns.split("\n") :
[ ]);
ASK.exclusionPatterns = typeof result.exclusionPatterns != "undefined" ?
result.exclusionPatterns.split("\n") :
[ ];
recalculatePatternEffects();
@@ -125,6 +121,7 @@ function updateUIState() {
function initialize() {
window.ASK = { };

// Retrieve saved settings.
chrome.tabs.query({currentWindow: true, active: true}, (tabs) => {
ASK.activeTabLocation = tabs[0].url;
chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ], (result) => {
@@ -133,17 +130,17 @@ function initialize() {
});
});

// Listener for main button.
document.querySelector("button.main-button").addActivateEvent((event) => {
toggleState();

let matchingPatterns = ASK.matchingPatterns.join("\n");
let exclusionPatterns = ASK.exclusionPatterns.join("\n");
let mode = ASK.mode;
chrome.storage.sync.set({
"matchingPatterns": matchingPatterns,
"exclusionPatterns": exclusionPatterns,
"mode": mode
}, () => {
var changes = {
"exclusionPatterns": ASK.exclusionPatterns.join("\n"),
"mode": ASK.mode
};
if (ASK.mode == "blacklist")
changes.matchingPatterns = ASK.matchingPatterns.join("\n");
chrome.storage.sync.set(changes, () => {
updateUIState();
let reloadButton = document.querySelector("button.reload-button");
if (ASK.pageMatched && !ASK.pageExcluded) {
@@ -155,11 +152,12 @@ function initialize() {
});
});

// Listener for Options button.
document.querySelector("button.options-button").addActivateEvent(() => {
chrome.runtime.openOptionsPage(null);
});

// Listener for reload button (appears when sticky-killing is toggled OFF).
document.querySelector("button.reload-button").addActivateEvent(() => {
chrome.tabs.update(null, { url: ASK.activeTabLocation });
window.close();

Ładowanie…
Anuluj
Zapisz