Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality (no-nonsense JS) #2650

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
aacda82
Remove `=== true` and `!== false`
4yman-0 Nov 2, 2024
2b80db5
less nonsense
4yman-0 Nov 2, 2024
b84a0ec
remove ESLint errors
4yman-0 Nov 2, 2024
63edbd5
remove ESLint errors #2
4yman-0 Nov 2, 2024
df9b610
fix ident etc
4yman-0 Nov 2, 2024
1f0e708
Use vscode format (can make code ugly)
4yman-0 Nov 3, 2024
c96a201
Merge branch 'master' into code-quality-experiment
4yman-0 Nov 9, 2024
1463228
Update
4yman-0 Nov 10, 2024
6ee1683
Update
4yman-0 Nov 11, 2024
fd05b18
Fix menu size
4yman-0 Nov 12, 2024
9388443
satus - Use grid for section
4yman-0 Nov 15, 2024
e313e06
satus - Attempt fixing
4yman-0 Nov 15, 2024
6abc84e
satus - Attempt fixing (again)
4yman-0 Nov 15, 2024
2a4ae1b
Add margin to grid
4yman-0 Nov 15, 2024
a9fff72
Go back to flex (w/ %)
4yman-0 Nov 18, 2024
e5c2f3c
Remove more CI Warnings
4yman-0 Nov 18, 2024
7ac6299
Merge branch 'master' into options-max-size
4yman-0 Dec 1, 2024
632cead
Merge branch 'master' into options-max-size
4yman-0 Dec 5, 2024
0271800
Merge branch 'master' into code-quality-experiment
4yman-0 Dec 5, 2024
9493130
New README
4yman-0 Dec 5, 2024
baf359a
Fix links. Add browser stores
4yman-0 Dec 5, 2024
63ab124
Add development stuff
4yman-0 Dec 5, 2024
32e2968
Fix EXxtensions section
4yman-0 Dec 5, 2024
369ea36
Merge branch 'master' into new-readme-experiment
4yman-0 Dec 6, 2024
1dd23ef
Update README headings
4yman-0 Dec 6, 2024
7f0967c
Update README.md
4yman-0 Dec 9, 2024
a60612c
Merge branch 'master' into code-quality-experiment
4yman-0 Dec 10, 2024
631a229
Merge branch 'code-charity:master' into options-max-size
4yman-0 Dec 12, 2024
60b6f95
Fix ESlint
4yman-0 Dec 12, 2024
128e0b6
Fix undefined globals
4yman-0 Dec 12, 2024
f640989
Add PrettierJS
4yman-0 Dec 12, 2024
3d66340
Move Dependencies to DevDependencies
4yman-0 Dec 12, 2024
6b9e14c
Merge branch 'master' into options-max-size
4yman-0 Dec 13, 2024
369da9b
Merge branch 'code-charity:master' into prettier-eslint
4yman-0 Dec 13, 2024
8681561
Use Prettier and ESLint
4yman-0 Dec 13, 2024
04e5dbc
Options max size
4yman-0 Dec 13, 2024
a1028bf
New README
4yman-0 Dec 13, 2024
632d4fc
Merge branch 'v5' into code-quality-experiment
4yman-0 Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 174 additions & 311 deletions .github/README.md

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions .github/workflows/eslint_csslint_jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: npm install --force

- name: Run eslint
run: npx eslint --config=tests/eslint_rules.config.mjs
run: npx eslint
continue-on-error: true

# - name: Run JSLint
Expand All @@ -40,11 +40,9 @@ jobs:
- name: Run npm test
run: npm test

- name: Install csslint using npm
run: npm install -g csslint@1.0.5
# - name: Install csslint using npm
# run: npm install -g csslint@1.0.5

# - name: Lint CSS files
# run: |
# for file in $(grep -rl --include='*.css' '' ./); do npx csslint --config tests/csslint_rules.json "$file"; done


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
113 changes: 58 additions & 55 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@
// const keepAliveInterval = setInterval(() => chrome.runtime.sendMessage({ status: 'keep-alive' }), 29.5 * 1000);

/* Sidepanel Option
chrome.storage.local.get('improvedTubeSidePanel', function (result) {
if ( result.improvedTubeSidePanel && result.improvedTubeSidePanel === true) {
chrome.storage.local.get('improvedTubeSidePanel', result => {
if (result.improvedTubeSidePanel) {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true })
} else {chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false }) }
} else {
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: false })
}
});
*/
/*---------------------------
# IMPORTING OLD (renamed) SETTINGS (Each one is mostly needed once, but fine to stay unlimited. Legacy.)
-----------------------------*/
chrome.runtime.onInstalled.addListener(function (installed) {
chrome.runtime.onInstalled.addListener(installed => {
if (installed.reason == 'update') {
// var thisVersion = chrome.runtime.getManifest().version;
// console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!");
chrome.storage.local.get('description', function (result) {
//var thisVersion = chrome.runtime.getManifest().version;
//console.log("Updated from " + installed.previousVersion + " to " + thisVersion + "!");
chrome.storage.local.get('description', result => {
if (result.description === 'classic_expanded') {
chrome.storage.local.set({description: 'expanded'});
}
});
});
// 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)) {
// Validate and move to new name
for (const [name, keys] of Object.entries(result)) {
if (!keys) continue;
let newKeys = {},
newName = name.replace('shortcut_', 'shortcut_quality_');
Expand All @@ -54,44 +56,44 @@ 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 (const [name, value] of Object.entries(result)) {
const newName = `shortcuts_${name}`;
chrome.storage.local.set({[newName]: value});
}
chrome.storage.local.remove(Object.keys(result));
});
chrome.storage.local.get('player_autoplay', function (result) {
if (result.player_autoplay === false) {
chrome.storage.local.get('player_autoplay', result => {
if (!result.player_autoplay) {
chrome.storage.local.set({player_autoplay_disable: true});
chrome.storage.local.remove(['player_autoplay']);
}
});
chrome.storage.local.get('channel_default_tab', function (result) {
chrome.storage.local.get('channel_default_tab', result => {
if (result.channel_default_tab === '/home') {
chrome.storage.local.set({channel_default_tab: '/'});
}
});
chrome.storage.local.get('player_quality', function (result) {
chrome.storage.local.get('player_quality', result => {
if (result.player_quality === 'auto') {
chrome.storage.local.get('player_quality_auto', function (result) {
chrome.storage.local.get('player_quality_auto', result => {
if (result.player_quality_auto !== 'migrated') {
chrome.storage.local.set({player_quality: 'disabled'});
chrome.storage.local.set({player_quality_auto: 'migrated'});
}
});
}
});
chrome.storage.local.get('hideSubscribe', function (result) {
if (result.hideSubscribe === true) {
chrome.storage.local.get('hideSubscribe', result => {
if (result.hideSubscribe) {
chrome.storage.local.set({subscribe: 'hidden'});
chrome.storage.local.remove(['hideSubscribe']);
}
});
chrome.storage.local.get('limit_page_width', function (result) {
if (result.limit_page_width === false) {
chrome.storage.local.get('limit_page_width', result => {
if (!result.limit_page_width) {
chrome.storage.local.set({no_page_margin: true});
chrome.storage.local.remove(['limit_page_width']);
chrome.storage.local.get('player_size', function (r) {
chrome.storage.local.get('player_size', r => {
if (r.player_size == 'full_window' || r.player_size == 'fit_to_window') {
chrome.storage.local.set({player_size: 'max_width'});
}
Expand All @@ -105,9 +107,9 @@ chrome.runtime.onInstalled.addListener(function (installed) {
if (navigator.userAgent.indexOf('Safari') !== -1
&& (!/Windows|Chrom/.test(navigator.userAgent)
|| /Macintosh|iPhone/.test(navigator.userAgent))) {
chrome.storage.local.set({below_player_pip: false})
chrome.storage.local.set({below_player_pip: false});
// still needed? (are screenshots broken in Safari?):
chrome.storage.local.set({below_player_screenshot: false})
chrome.storage.local.set({below_player_screenshot: false});
}
// console.log('Thanks for installing!');
}
Expand All @@ -117,20 +119,20 @@ chrome.runtime.onInstalled.addListener(function (installed) {
--------------------------------------------------------------*/
function getLocale (language, callback) {
language = language.replace('-', '_');
fetch('_locales/' + language.substring(0, 2) + '/messages.json').then(function (response) {
fetch('_locales/' + language.substring(0, 2) + '/messages.json').then(response => {
if (response.ok) {
response.json().then(callback);
} else {
fetch('_locales/' + language.substring(0, 2) + '/messages.json').then(function (response) {
fetch('_locales/' + language.substring(0, 2) + '/messages.json').then(response => {
if (response.ok) {
response.json().then(callback);
} else {
getLocale('en', callback);
}
}).catch(function () { getLocale('en', callback); });
}).catch(() => {getLocale('en', callback);});
getLocale('en', callback);
}
}).catch(function () {
}).catch(() => {
getLocale('en', callback);
});
}
Expand All @@ -139,7 +141,7 @@ function getLocale (language, callback) {
--------------------------------------------------------------*/
function updateContextMenu (language) {
if (!language || language === 'default') language = chrome.i18n.getUILanguage();
getLocale(language, function (response) {
getLocale(language, response => {
const items = [
'donate',
'rateMe',
Expand All @@ -157,7 +159,7 @@ function updateContextMenu (language) {
// contexts: ['browser_action'] //manifest2
});
}
chrome.contextMenus.onClicked.addListener(function (info) {
chrome.contextMenus.onClicked.addListener(info => {
const links = [
'https://www.improvedtube.com/donate',
'https://chrome.google.com/webstore/detail/improve-youtube-video-you/bnomihfieiccainjcjblhegjgglakjdd',
Expand All @@ -168,15 +170,17 @@ function updateContextMenu (language) {
});
});
}
chrome.runtime.onInstalled.addListener(function () {
chrome.storage.local.get(function (items) {
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.get(items => {
updateContextMenu(items.language);
});
});

chrome.storage.onChanged.addListener(function (changes) {
if (changes?.language) updateContextMenu(changes.language.newValue);
if (changes?.improvedTubeSidebar) chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: changes.language.newValue});
chrome.storage.onChanged.addListener(changes => {
if (changes?.language)
updateContextMenu(changes.language.newValue);
if (changes?.improvedTubeSidebar)
chrome.sidePanel.setPanelBehavior({openPanelOnActionClick: changes.language.newValue});
});
/*--------------------------------------------------------------
# TAB Helper, prune stale connected tabs
Expand All @@ -187,31 +191,31 @@ let tabConnected = {},
windowId;

function tabPrune (callback) {
chrome.tabs.query({ url: 'https://www.youtube.com/*' }).then(function (tabs) {
chrome.tabs.query({ url: 'https://www.youtube.com/*' }).then(tabs => {
let tabIds = [];
for (let tab of tabs) {
for (const tab of tabs) {
if (!tab.discarded && tabConnected[tab.id]) {
tabIds.push(tab.id);
}
}
for (let id in tabConnected) {
for (const id in tabConnected) {
if (!tabIds.includes(Number(id))) {
delete tabConnected[id];
}
}
callback();
}, function () { console.log("Error querying Tabs") });
}, () => { console.log("Error querying Tabs") });
};
/*--------------------------------------------------------------
# TAB FOCUS/BLUR
commented out console.log left intentionally, to help understand
https://issues.chromium.org/issues/41116352
--------------------------------------------------------------*/
chrome.tabs.onActivated.addListener(function (activeInfo) {
chrome.tabs.onActivated.addListener(activeInfo => {
tabPrev = tab;
tab = activeInfo;
//console.log('activeInfo', windowId, tabPrev, tab);
tabPrune(function () {
tabPrune(() => {
if (windowId == tabPrev.windowId) {
if (tabConnected[tabPrev.tabId]) {
chrome.tabs.sendMessage(tabPrev.tabId, {action: 'blur'});
Expand All @@ -224,10 +228,9 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
}
});
});
chrome.windows.onFocusChanged.addListener(function (wId) {
windowId = wId;
chrome.windows.onFocusChanged.addListener(windowId => {
//console.log('onFocusChanged', windowId, tabPrev, tab);
tabPrune(function () {
tabPrune(() => {
if (windowId != tab.windowId && tab.tabId && !tab.blur && tabConnected[tab.tabId]) {
tab.blur = true;
chrome.tabs.sendMessage(tab.tabId, {action: 'blur'});
Expand All @@ -242,13 +245,13 @@ chrome.windows.onFocusChanged.addListener(function (wId) {
/*--------------------------------------------------------------
# MESSAGE LISTENER
--------------------------------------------------------------*/
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
//console.log(message);
//console.log(sender);

switch (message.action || message.name || message) {
case 'play':
tabPrune(function () {
tabPrune(() => {
for (let id in tabConnected) {
id = Number(id);
if (id != sender.tab.id) {
Expand Down Expand Up @@ -279,15 +282,15 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
active: true
}, ts => {
const tID = ts[0]?.id,
data = { type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: 0,
top: 20
}

if (tID) {data.tabId = tID;}
data = {
type: 'popup',
state: w.state,
width: parseInt(message.width, 10),
height: parseInt(message.height, 10),
left: 0,
top: 20
};
if (tID) data.tabId = tID;
chrome.windows.create(data);

//append to title?
Expand Down
28 changes: 28 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from "@eslint/js";
import globals from "globals";

const customGlobals = {
extension: "writable",
ImprovedTube: "writable",
chrome: "readonly",
}

export default [

js.configs.recommended,
{
languageOptions: {
globals: {
...customGlobals,
...globals.browser,
},
},
rules: {
"no-unused-vars": [
"error",
{ destructuredArrayIgnorePattern: "^_" },
],
},
},

];
8 changes: 0 additions & 8 deletions jest.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"testPathIgnorePatterns": [
"/node_modules/"
],
"testMatch": [
"**/tests/**/*.js"
]
}
Loading
Loading