Skip to content

Commit

Permalink
Use var because the original author used it
Browse files Browse the repository at this point in the history
  • Loading branch information
4yman-0 committed Nov 4, 2024
1 parent 1f0e708 commit 9bc811e
Show file tree
Hide file tree
Showing 23 changed files with 334 additions and 334 deletions.
34 changes: 17 additions & 17 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/*-----# Persistent Serviceworker:
"Manifest2 Background.js"-----*/
// Periodic "keep-alive" message every 29.5 seconds
// const keepAliveInterval = setInterval(() => chrome.runtime.sendMessage({ status: 'keep-alive' }), 29.5 * 1000);
// var keepAliveInterval = setInterval(() => chrome.runtime.sendMessage({ status: 'keep-alive' }), 29.5 * 1000);

/* Sidepanel Option
chrome.storage.local.get('improvedTubeSidePanel', function (result) {
Expand All @@ -38,11 +38,11 @@ chrome.runtime.onInstalled.addListener(function (installed) {
// Shortcut renames:
chrome.storage.local.get(['shortcut_auto', 'shortcut_144p', 'shortcut_240p', 'shortcut_360p', 'shortcut_480p', 'shortcut_720p', 'shortcut_1080p', 'shortcut_1440p', 'shortcut_2160p', 'shortcut_2880p', 'shortcut_4320p'], function (result) {
// Validate and move to new name
for (let [name, keys] of Object.entries(result)) {
for (var [name, keys] of Object.entries(result)) {
if (!keys) continue;
let newKeys = {},
var newKeys = {},
newName = name.replace('shortcut_', 'shortcut_quality_');
for (const button of ['alt', 'ctrl', 'shift', 'wheel', 'toggle']) {
for (var button of ['alt', 'ctrl', 'shift', 'wheel', 'toggle']) {
if (keys[button]) newKeys[button] = keys[button];
}
if (keys['keys'] && Object.keys(keys['keys'])?.length) {
Expand All @@ -54,8 +54,8 @@ chrome.runtime.onInstalled.addListener(function (installed) {
chrome.storage.local.remove(Object.keys(result));
});
chrome.storage.local.get(['volume_step', 'playback_speed_step'], function (result) {
for (let [name, value] of Object.entries(result)) {
let newName = 'shortcuts_' + name;
for (var [name, value] of Object.entries(result)) {
var newName = 'shortcuts_' + name;
chrome.storage.local.set({[newName]: value});
}
chrome.storage.local.remove(Object.keys(result));
Expand Down Expand Up @@ -140,15 +140,15 @@ function getLocale (language, callback) {
function updateContextMenu (language) {
if (!language || language === 'default') language = chrome.i18n.getUILanguage();
getLocale(language, function (response) {
const items = [
var items = [
'donate',
'rateMe',
'GitHub'
];
chrome.contextMenus.removeAll();

for (const [index, item] of items.entries()) {
const text = response?.[item]?.message || item;
for (var [index, item] of items.entries()) {
var text = response?.[item]?.message || item;

chrome.contextMenus.create({
id: String(index),
Expand All @@ -158,7 +158,7 @@ function updateContextMenu (language) {
});
}
chrome.contextMenus.onClicked.addListener(function (info) {
const links = [
var links = [
'https://www.improvedtube.com/donate',
'https://chrome.google.com/webstore/detail/improve-youtube-video-you/bnomihfieiccainjcjblhegjgglakjdd',
'https://github.com/code4charity/YouTube-Extension'
Expand All @@ -181,20 +181,20 @@ chrome.storage.onChanged.addListener(function (changes) {
/*--------------------------------------------------------------
# TAB Helper, prune stale connected tabs
--------------------------------------------------------------*/
let tabConnected = {},
var tabConnected = {},
tab = {},
tabPrev = {},
windowId;

function tabPrune (callback) {
chrome.tabs.query({ url: 'https://www.youtube.com/*' }).then(function (tabs) {
let tabIds = [];
for (let tab of tabs) {
var tabIds = [];
for (var tab of tabs) {
if (!tab.discarded && tabConnected[tab.id]) {
tabIds.push(tab.id);
}
}
for (let id in tabConnected) {
for (var id in tabConnected) {
if (!tabIds.includes(Number(id))) {
delete tabConnected[id];
}
Expand Down Expand Up @@ -249,7 +249,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
switch (message.action || message.name || message) {
case 'play':
tabPrune(function () {
for (let id in tabConnected) {
for (var id in tabConnected) {
id = Number(id);
if (id != sender.tab.id) {
chrome.tabs.sendMessage(id, {action: "another-video-started-playing"});
Expand Down Expand Up @@ -278,7 +278,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
windowId: w.id,
active: true
}, ts => {
const tID = ts[0]?.id,
var tID = ts[0]?.id,
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
Expand Down Expand Up @@ -308,7 +308,7 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
}, function (granted) {
if (granted) {
try {
const blob = new Blob([JSON.stringify(message.value)], {
var blob = new Blob([JSON.stringify(message.value)], {
type: 'application/json;charset=utf-8'
});
chrome.downloads.download({
Expand Down
2 changes: 1 addition & 1 deletion js&css/extension/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ extension.storage.load = function (callback) {
chrome.storage.local.set({ theme: 'dark' });
}

for (const key in items) {
for (var key in items) {
document.documentElement.setAttribute('it-' + key.replace(/_/g, '-'), items[key]);
}

Expand Down
22 changes: 11 additions & 11 deletions js&css/extension/www.youtube.com/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ extension.features.popupWindowButtons = function (event) {
if (ytPlayer) {width = ytPlayer.offsetWidth * 0.65; height = ytPlayer.offsetHeight * 0.65}

Check failure on line 254 in js&css/extension/www.youtube.com/general/general.js

View workflow job for this annotation

GitHub Actions / lint-and-test

Closing curly brace does not appear on the same line as the subsequent block
else { width = innerWidth * 0.4; height = innerHeight * 0.4; }
if (!ytPlayer) {
let shorts = /short/.test(this.parentElement.href);
let vertical = false;
var shorts = /short/.test(this.parentElement.href);
var vertical = false;
if (width / height < 1) { vertical = true }
if (!vertical && shorts) { width = height * 0.6}
if (vertical && !shorts) { height = width * 0.6}
Expand Down Expand Up @@ -532,8 +532,8 @@ extension.features.disableThumbnailPlayback = function (event) {
extension.features.openNewTab = function () {
if (extension.storage.get("open_new_tab") ) {
window.onload = function () {
const searchButton = document.querySelector("button#search-icon-legacy");
const inputField = document.querySelector("input#search");
var searchButton = document.querySelector("button#search-icon-legacy");
var inputField = document.querySelector("input#search");

searchButton.addEventListener("mousedown", (event) => {

Check failure on line 538 in js&css/extension/www.youtube.com/general/general.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'event' is defined but never used
performSearchNewTab(inputField.value);
Expand All @@ -544,23 +544,23 @@ extension.features.openNewTab = function () {
}
});

let searchedAlready = false;
var searchedAlready = false;
inputField.addEventListener("focus", function () {
searchedAlready = false;
const observer = new MutationObserver(applySuggestionListeners);
const container = document.querySelector("div[style*='position: fixed'] ul[role='listbox']");
var observer = new MutationObserver(applySuggestionListeners);
var container = document.querySelector("div[style*='position: fixed'] ul[role='listbox']");
if (container) observer.observe(container, { attributes: true, childList: true, subtree: true });
});

inputField.addEventListener("input", () => searchedAlready = false);

function applySuggestionListeners () {
const suggestionContainers = document.querySelectorAll("div[class^='sbqs'], div[class^='sbpqs']");
var suggestionContainers = document.querySelectorAll("div[class^='sbqs'], div[class^='sbpqs']");
suggestionContainers.forEach((suggestionsContainer) => {
suggestionsContainer.addEventListener("mousedown", (event) => {
const suggestionListItem = event.target.closest("li[role='presentation']");
var suggestionListItem = event.target.closest("li[role='presentation']");
if (suggestionListItem && !searchedAlready) {
const query = suggestionListItem.querySelector("b").textContent
var query = suggestionListItem.querySelector("b").textContent
performSearchNewTab(inputField.value + query);
searchedAlready = true;
}
Expand All @@ -571,7 +571,7 @@ extension.features.openNewTab = function () {
function performSearchNewTab (query) {
inputField.value = "";
inputField.focus();
const newTabURL = `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`;
var newTabURL = `https://www.youtube.com/results?search_query=${encodeURIComponent(query)}`;
window.open(newTabURL, '_blank');
}
}
Expand Down
12 changes: 6 additions & 6 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ document.addEventListener('it-message-from-extension', function () {
ImprovedTube.storage = message.storage;

if (ImprovedTube.storage.block_vp9 || ImprovedTube.storage.block_av1 || ImprovedTube.storage.block_h264) {
let atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' },
var atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' },
codec = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all ? all + '|' : '') + atlas[key]) : all
}, '');
Expand All @@ -207,11 +207,11 @@ document.addEventListener('it-message-from-extension', function () {

// REACTION OR VISUAL FEEDBACK WHEN THE USER CHANGES A SETTING (already automated for our CSS features):
} else if (message.action === 'storage-changed') {
let camelized_key = message.camelizedKey;
var camelized_key = message.camelizedKey;

ImprovedTube.storage[message.key] = message.value;
if (['block_vp9', 'block_h264', 'block_av1'].includes(message.key)) {
let atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' }
var atlas = { block_vp9: 'vp9|vp09', block_h264: 'avc1', block_av1: 'av01' }

Check failure on line 214 in js&css/web-accessible/core.js

View workflow job for this annotation

GitHub Actions / lint-and-test

'atlas' is already defined
localStorage['it-codec'] = Object.keys(atlas).reduce(function (all, key) {
return ImprovedTube.storage[key] ? ((all ? all + '|' : '') + atlas[key]) : all
}, '');
Expand Down Expand Up @@ -287,7 +287,7 @@ document.addEventListener('it-message-from-extension', function () {

case 'forcedTheaterMode':
if (ImprovedTube.storage.forced_theater_mode === false && ImprovedTube.elements.ytd_watch && ImprovedTube.elements.player) {
const button = ImprovedTube.elements.player.querySelector("button.ytp-size-button");
var button = ImprovedTube.elements.player.querySelector("button.ytp-size-button");
if (button && ImprovedTube.elements.ytd_watch.theater) {
ImprovedTube.elements.ytd_watch.theater = false;
setTimeout(function () { button.click(); }, 100);
Expand Down Expand Up @@ -336,7 +336,7 @@ document.addEventListener('it-message-from-extension', function () {
case 'playerHamburgerButton':
if (ImprovedTube.storage.player_hamburger_button == false) {
document.querySelector('.custom-hamburger-menu')?.remove();
let rightControls = document.querySelector('.html5-video-player')?.querySelector('.ytp-right-controls');
var rightControls = document.querySelector('.html5-video-player')?.querySelector('.ytp-right-controls');
if (rightControls) {
rightControls.style.setProperty('padding-right', ''); // Restoring the original padding:
rightControls.style.setProperty('display', 'flex');
Expand Down Expand Up @@ -437,7 +437,7 @@ document.addEventListener('it-message-from-extension', function () {
} else if (message.deleteCookies) {
ImprovedTube.deleteYoutubeCookies();
} else if (message.responseOptionsUrl) {
const iframe = document.querySelector('.it-button__iframe');
var iframe = document.querySelector('.it-button__iframe');

if (iframe) {
iframe.src = message.responseOptionsUrl;
Expand Down
28 changes: 14 additions & 14 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ ImprovedTube.childHandler = function (node) {
}

/*
const DOM_filter = /^(SCRIPT|DOM-IF|DOM-REPEAT|svg|SPAN|#text|#comment|yt-icon-shape|iron-iconset-svg)$/;
var DOM_filter = /^(SCRIPT|DOM-IF|DOM-REPEAT|svg|SPAN|#text|#comment|yt-icon-shape|iron-iconset-svg)$/;
ImprovedTube.childHandler = function (node) { //console.log(node.nodeName);
if (DOM_filter.test(node.nodeName)) { return; }
var children = node.children;
ImprovedTube.ytElementsHandler(node);
if (children) {
let i = 0;
for (const child of children) {
var i = 0;
for (var child of children) {
ImprovedTube.childHandler(children[i]);
//console.log("node.nodeName:CHILD-"+i+":"+children[i].id+",class:"+children[i].className+","+children[i]+"("+children[i].nodeName+")");
i++;
Expand All @@ -33,7 +33,7 @@ ImprovedTube.childHandler = function (node) { //console.log(node.nodeName);
}; */

ImprovedTube.ytElementsHandler = function (node) {
const name = node.nodeName,
var name = node.nodeName,
id = node.id;

if (name === 'A') {
Expand Down Expand Up @@ -430,7 +430,7 @@ ImprovedTube.playerOnPause = function (event) {
if (document.documentElement.dataset.pageType === 'video'
&& (ImprovedTube.storage.description === "expanded" || ImprovedTube.storage.transcript || ImprovedTube.storage.chapters)) {
ImprovedTube.forbidFocus = function (ms) {
const originalFocus = HTMLElement.prototype.focus; // Backing up default method - other methods: Element.prototype.scrollIntoView window.scrollTo window.scrollBy
var originalFocus = HTMLElement.prototype.focus; // Backing up default method - other methods: Element.prototype.scrollIntoView window.scrollTo window.scrollBy
// Override YouTube's scroll method:
HTMLElement.prototype.focus = function () { console.log("Preventing YouTube's scripted scrolling, when expanding the video description for you"); }
if (document.hidden) ms = 3 * ms;
Expand Down Expand Up @@ -540,16 +540,16 @@ ImprovedTube.getCookieValueByName = function (name) {
};

ImprovedTube.getPrefCookieValueByName = function (name) {
let prefs = this.getParams(this.getCookieValueByName('PREF'));
var prefs = this.getParams(this.getCookieValueByName('PREF'));
return prefs[name];
};

// set PREF cookie name=value or delete name if value == null
ImprovedTube.setPrefCookieValueByName = function (name, value) {
let originalPref = this.getCookieValueByName('PREF');
let prefs = this.getParams(originalPref);
let newPrefs = '';
let ampersant = '';
var originalPref = this.getCookieValueByName('PREF');
var prefs = this.getParams(originalPref);
var newPrefs = '';
var ampersant = '';

if (name == 'f6' && prefs[name] & 1) {
// f6 holds other settings, possible values 80000 80001 400 401 1 none
Expand All @@ -559,7 +559,7 @@ ImprovedTube.setPrefCookieValueByName = function (name, value) {
prefs[name] = value;
}

for (let pref in prefs) {
for (var pref in prefs) {
if (prefs[pref]) {
newPrefs += ampersant + pref + '=' + prefs[pref];
ampersant = '&';
Expand All @@ -580,13 +580,13 @@ ImprovedTube.setCookie = function (name, value) {
};

ImprovedTube.createIconButton = function (options) {
const button = options.href ? document.createElement('a') : document.createElement('button'),
var button = options.href ? document.createElement('a') : document.createElement('button'),
svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
path = document.createElementNS('http://www.w3.org/2000/svg', 'path'),
type = this.button_icons[options.type];

for (const attr of type.svg) svg.setAttribute(attr[0], attr[1]);
for (const attr of type.path) path.setAttribute(attr[0], attr[1]);
for (var attr of type.svg) svg.setAttribute(attr[0], attr[1]);
for (var attr of type.path) path.setAttribute(attr[0], attr[1]);

svg.appendChild(path);
button.appendChild(svg);
Expand Down
6 changes: 3 additions & 3 deletions js&css/web-accessible/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ ImprovedTube.observer = new MutationObserver(function (mutationList) {

/*
//console.log("--- p FOR PARENT, c FOR CHILD, r FOR REMOVED :");
let i = 0; for (const mutated of mutationList) {
var i = 0; for (var mutated of mutationList) {
if (mutated.type === 'childList') {
// if (/^(SCRIPT|DOM-IF|DOM-REPEAT|svg|SPAN|yt-icon-shape)$/.test(mutated.target.nodeName)) {i++; continue; }
// ImprovedTube.ytElementsHandler(mutated.target);
// console.log("p"+i+":"+mutated.target.id+",class:"+mutated.target.className+","+mutated.target+"("+mutated.target.nodeName+")");
let j = 0; for (const node of mutated.addedNodes) {
var j = 0; for (var node of mutated.addedNodes) {
ImprovedTube.childHandler(node);
//console.log("p"+i+"c"+j+":"+node.id+",class:"+node.className+","+node+"("+node.nodeName+")");
j++;}
let r = 0; for (const node of mutated.removedNodes){ //might fix our other playlist buttons equally?
var r = 0; for (var node of mutated.removedNodes){ //might fix our other playlist buttons equally?
if(node.nodeName === 'BUTTON' && node.id === 'it-popup-playlist-button') ImprovedTube.playlistPopup();
//console.log("p"+i+"removed"+r+":"+node.id+",class:"+node.className+","+node+"("+node.nodeName+")"+"(from:"+mutated.target.id+",class:"+mutated.target.className+","+mutated.target+"("+mutated.target.nodeName+")");
r++;}
Expand Down
Loading

0 comments on commit 9bc811e

Please sign in to comment.