diff --git a/blocker.js b/blocker.js index 03bd9c4..365c807 100644 --- a/blocker.js +++ b/blocker.js @@ -12,6 +12,12 @@ function Flatten(str) { return str.toLowerCase().replace(/\s/g, '') } +function GetConfigSettings() { + chrome.storage.local.get(['blockSelfPromotion'], function (result) { + blockSelfPromotion = result.blockSelfPromotion || false; + }); +} + async function LoadJSON() { // Fetch the embedded JSON files try { const [stringsData, selectorsData] = await Promise.all([ @@ -65,9 +71,6 @@ function SearchAndDestroySponsors() { let newText = sentences .filter(sentence => !Flatten(sentence).includes(str)) .join(""); - - // Preserve the original line breaks - newText = newText.replace(/\n/g, '
'); contentElement.innerHTML = newText; } } @@ -99,10 +102,17 @@ function splitKeepDelimiter(input, regex) { return result; } +// Collect debug info for issue reporting +function savePageInfo() { + const pageURL = window.location.href; // Get the URL of the tab + const pageTitle = document.title; // Get the title of the tab + chrome.storage.local.set({ pageURL: pageURL, pageTitle: pageTitle }); +} - -SearchAndDestroySponsors() // Run initially +// Call the function to save page info +savePageInfo(); +GetConfigSettings() // Look for changes in the DOM new MutationObserver(SearchAndDestroySponsors) diff --git a/manifest V3.json b/manifest V3.json index 849204e..5715a42 100644 --- a/manifest V3.json +++ b/manifest V3.json @@ -1,17 +1,21 @@ { "manifest_version": 3, "name": "Block Sponsor Comments", - "version": "1.4.3", - "description": "Browser extension to remove sponsors from youtube descriptions and comments.", + "version": "1.5.0", + "description": "Browser extension to remove sponsors from YouTube descriptions and comments.", "host_permissions": [ "*://*.youtube.com/*" ], + "action": { + "default_popup": "settings.html" + }, "content_scripts": [{ "matches": ["https://www.youtube.com/*"], "js": ["blocker.js"] }], "web_accessible_resources": [{ "resources": [ + "settings.html", "*.json" ], "matches": [ diff --git a/manifest.json b/manifest.json index c36913c..9b13a4d 100644 --- a/manifest.json +++ b/manifest.json @@ -1,17 +1,22 @@ { "manifest_version": 2, "name": "Block Sponsor Comments", - "version": "1.4.3", - "description": "Browser extension to remove sponsors from youtube descriptions and comments.", + "version": "1.5.0", + "description": "Browser extension to remove sponsors from YouTube descriptions and comments.", "permissions": [ - "*://*.youtube.com/*" + "*://*.youtube.com/*", + "storage" ], + "browser_action": { + "default_popup": "settings.html" + }, "content_scripts": [{ "matches": ["https://www.youtube.com/*"], "js": ["blocker.js"], "run_at": "document_idle" }], "web_accessible_resources": [ + "settings.html", "*.json" ], "icons": { diff --git a/settings.html b/settings.html new file mode 100644 index 0000000..568bcca --- /dev/null +++ b/settings.html @@ -0,0 +1,61 @@ + + + + + + + + + +
+

Settings

+ +
+ + +

+ + + + + + + + +
\ No newline at end of file diff --git a/settings.js b/settings.js new file mode 100644 index 0000000..8f87ac5 --- /dev/null +++ b/settings.js @@ -0,0 +1,51 @@ +document.addEventListener('DOMContentLoaded', function () { + const selfPromotionCheckbox = document.getElementById('self-promotion'); + const showIssueFormButton = document.getElementById('show-issue-form'); + const submitIssueButton = document.getElementById('submit-issue'); + const issueForm = document.getElementById('issue-form'); + const currentTitleInput = document.getElementById('current-title'); + const currentUrlInput = document.getElementById('current-url'); + const extraNotesTextarea = document.getElementById('extra-notes'); + + // Load saved setting + chrome.storage.local.get(['blockSelfPromotion'], function (result) { + selfPromotionCheckbox.checked = result.blockSelfPromotion || false; + }); + + // Save setting when checkbox is clicked + selfPromotionCheckbox.addEventListener('change', function () { + chrome.storage.local.set({ blockSelfPromotion: this.checked }, function () { + }); + }); + + showIssueFormButton.addEventListener('click', () => { + issueForm.style.display = issueForm.style.display === 'none' ? 'block' : 'none'; + GetPageContext((pageTitle, pageURL) => { + currentTitleInput.value = pageTitle.replace(" - YouTube", "") + currentUrlInput.value = pageURL.replace("www.", "") + }) + }); + + // Function to get page context from chrome.storage.local + function GetPageContext(callback) { + chrome.storage.local.get(["pageURL", "pageTitle"], function (result) { + const pageTitle = result.pageTitle || ''; // Default to empty string if not found + const pageURL = result.pageURL || ''; // Default to empty string if not found + callback(pageTitle, pageURL); + }); + } + + // Event listener for the submit issue button + submitIssueButton.addEventListener('click', function () { + GetPageContext((pageTitle, pageURL) => { + const notes = extraNotesTextarea.value; + + // Create the GitHub issue URL with query parameters + const issueUrl = `https://github.com/MagicJinn/Block-Sponsor-Comments/issues/new?title=New+sponsor+at:+${encodeURIComponent(pageTitle)}&body=${encodeURIComponent(`URL: ${pageURL}\n\nNotes:\n${notes}`)}`; + + // Open the new issue URL in a new tab + window.open(issueUrl, '_blank'); + }); + }); + +}); \ No newline at end of file diff --git a/strings.json b/strings.json index 4dae55d..60a9591 100644 --- a/strings.json +++ b/strings.json @@ -129,10 +129,12 @@ "Hubspot", "Trade Coffee", "Lectric", - "displate" + "displate", + "GAMERSUPPS" ], "SelfPromotion": [ - "Patreon", - "lttstore" + "Patreon", + "lttstore", + "ayylienclothing" ] } \ No newline at end of file