Skip to content

Commit

Permalink
settings menu is in place and is cool and good
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicJinn committed Jul 29, 2024
1 parent 8372134 commit c463196
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 13 deletions.
20 changes: 15 additions & 5 deletions blocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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, '<br>');
contentElement.innerHTML = newText;
}
}
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions manifest V3.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
11 changes: 8 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
61 changes: 61 additions & 0 deletions settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
font-size: 16px;
font-family: 'Source Sans Pro';
width: 300px;
background-color: #181818;
color: white
}

.kofi-icon {
position: absolute;
right: 10px;
cursor: pointer;
}

#current-url,
#current-title {
background-color: #f0f0f0;
color: #666;
cursor: default;
}

h1 {
text-align: center;
}
</style>
</head>

<div class="settings-menu">
<h1>Settings</h1>

<div class="option">
<label for="self-promotion">Block Self Promotion</label>
<input type="checkbox" id="self-promotion" name="self-promotion">
</div><br>

<button id="show-issue-form">Submit issue with current watchpage</button>
<div id="issue-form" style="display: none;">
<input type="text" id="current-title" style="width:100%" placeholder="Current video Title">
<br>
<input type="text" id="current-url" style="width:100%" placeholder="Current video URL">
<br>
<textarea id="extra-notes" placeholder="Additional notes..."></textarea>
<br>
<div style="display: flex; align-items: center;">
<button id="submit-issue">Submit to GitHub</button>
<div style="font-size: 12px; margin-left: 8px">(Requires a GitHub account)</div>
</div>
</div>

<a href="https://ko-fi.com/magicjinn" target="_blank" class="kofi-icon">
<img src="https://ko-fi.com/favicon.ico" width="24" height="24">
</a>
<script src="settings.js"></script>
</div>
51 changes: 51 additions & 0 deletions settings.js
Original file line number Diff line number Diff line change
@@ -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');
});
});

});
8 changes: 5 additions & 3 deletions strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@
"Hubspot",
"Trade Coffee",
"Lectric",
"displate"
"displate",
"GAMERSUPPS"
],
"SelfPromotion": [
"Patreon",
"lttstore"
"Patreon",
"lttstore",
"ayylienclothing"
]
}

0 comments on commit c463196

Please sign in to comment.