diff --git a/background.js b/background.js index 689a6c7..679e6c8 100644 --- a/background.js +++ b/background.js @@ -36,6 +36,33 @@ chrome.runtime.onInstalled.addListener(function (detail) { if (detail.reason === 'update') { chrome.tabs.create({ url: 'https://getindie.wiki/changelog/?updated=true' }); } + + // Temporary function for 3.0 migration + // On update, set new default action settings: + if (detail.reason === 'update') { + chrome.storage.sync.get({ 'defaultWikiAction': null }, function (item) { + if (!item.defaultWikiAction) { + chrome.storage.sync.get({ 'defaultActionSettings': {} }, function (item) { + if (item.defaultActionSettings['EN']) { + chrome.storage.sync.set({ 'defaultWikiAction': item.defaultActionSettings['EN'] }); + } + }); + } + }); + chrome.storage.sync.get({ 'defaultSearchAction': null }, function (item) { + if (!item.defaultSearchAction) { + chrome.storage.sync.get({ 'defaultSearchFilterSettings': {} }, function (item) { + if (item.defaultSearchFilterSettings['EN']) { + if (item.defaultSearchFilterSettings['EN'] === 'true') { + chrome.storage.sync.set({ 'defaultSearchAction': 'replace' }); + } else if (item.defaultSearchFilterSettings['EN'] === 'false') { + chrome.storage.sync.set({ 'defaultSearchAction': 'disabled' }); + } + } + }); + } + }); + } }); if (chrome.declarativeNetRequest) { @@ -300,8 +327,8 @@ async function main(eventInfo) { let siteSetting = ''; if (settings.hasOwnProperty(id) && settings[id].hasOwnProperty('action')) { siteSetting = settings[id].action; - } else if (storage.defaultActionSettings && storage.defaultActionSettings[site.language]) { - siteSetting = storage.defaultActionSettings[site.language]; + } else if (storage.defaultWikiAction) { + siteSetting = storage.defaultWikiAction; } else { siteSetting = 'alert'; } diff --git a/content-search-filtering.js b/content-search-filtering.js index b2a16f3..23c3eea 100644 --- a/content-search-filtering.js +++ b/content-search-filtering.js @@ -266,15 +266,15 @@ function hideSearchResults(searchResultContainer, searchEngine, site) { searchRemovalNotice.appendChild(disableFilterButton); disableFilterButton.onclick = function (e) { if (e.target.textContent.includes('Stop')) { - chrome.storage.sync.get({ 'siteSettings': {} }, function (response) { - response.siteSettings.get(site.id).set('searchFilter', 'false'); - chrome.storage.sync.set({ 'siteSettings': response.siteSettings }); + chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) { + response.searchEngineSettings.get(site.id).set('action', 'disabled'); + chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings }); e.target.textContent = 'Re-enable filtering for ' + site.origin_group; }) } else { - chrome.storage.sync.get({ 'siteSettings': {} }, function (response) { - response.siteSettings.get(site.id).set('searchFilter', 'true'); - chrome.storage.sync.set({ 'siteSettings': response.siteSettings }); + chrome.storage.sync.get({ 'searchEngineSettings': {} }, function (response) { + response.searchEngineSettings.get(site.id).set('action', 'hide'); + chrome.storage.sync.set({ 'searchEngineSettings': response.searchEngineSettings }); e.target.textContent = 'Stop filtering ' + site.origin_group + ' in future searches'; }) } @@ -387,17 +387,17 @@ function filterSearchResults(searchResults, searchEngine, storage) { let site = matchingSites.find(site => site.origin_base_url === closestMatch); if (site) { // Get user's settings for the wiki - let settings = storage.siteSettings || {}; + let settings = storage.searchEngineSettings || {}; let id = site['id']; let searchFilterSetting = ''; - if (settings.hasOwnProperty(id) && settings[id].searchFilter) { - searchFilterSetting = settings[id].searchFilter; - } else if (storage.defaultSearchFilterSettings && storage.defaultSearchFilterSettings[site.language]) { - searchFilterSetting = storage.defaultSearchFilterSettings[site.language]; + if (settings.hasOwnProperty(id) && settings[id].action) { + searchFilterSetting = settings[id].action; + } else if (storage.defaultSearchAction) { + searchFilterSetting = storage.defaultSearchAction; } else { - searchFilterSetting = 'true'; + searchFilterSetting = 'replace'; } - if (searchFilterSetting === 'true') { + if (searchFilterSetting !== 'disabled') { // Output stylesheet if not already done if (filteredWikis.length === 0) { // Wait for head to be available @@ -419,7 +419,6 @@ function filterSearchResults(searchResults, searchEngine, storage) { } } - let cssQuery = ''; let searchResultContainer = null; switch (searchEngine) { case 'google': @@ -447,7 +446,7 @@ function filterSearchResults(searchResults, searchEngine, storage) { } if (searchResultContainer) { - if (storage.searchSetting === 'hide') { + if (searchFilterSetting === 'hide') { countFiltered += hideSearchResults(searchResultContainer, searchEngine, site); } else { countFiltered += redirectSearchResults(searchResultContainer, site, link); @@ -477,7 +476,7 @@ function main(mutations = null, observer = null) { // Check if extension is on: if ((storage.power ?? 'on') === 'on') { // Determine which search engine we're on - if ((storage.searchSetting ?? 'replace') !== 'nothing') { + if ((storage.action ?? 'replace') !== 'nothing') { if (currentURL.hostname.includes('www.google.')) { // Function to filter search results in Google function filterGoogle() { diff --git a/guide.html b/guide.html index 41b8315..435ec94 100644 --- a/guide.html +++ b/guide.html @@ -111,40 +111,13 @@

Global settings help

- There are four global settings options: + There are three global settings options: