Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cvan committed Apr 4, 2019
1 parent 211e2de commit dac2b13
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions app/src/main/assets/web_extensions/youtube_webcompat/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,11 @@
return;
}

// let script = document.head.querySelector('script[id="content-script"]');
// if (!script) {
// script = document.createElement('script');
// script.id = 'content-script';
// script.src = 'https://cvan.ngrok.io/content-script.js';
// document.head.appendChild(script);
// }

var prefs = {
hd: false,
once: false,
higher: false,
quality: 144,
quality: 'hd1440',
log: true,
qualityLabels: {
4320: 'highres', // 8K / 4320p / QUHD
Expand All @@ -47,15 +39,12 @@
Object.assign(script.dataset, prefs);
delete script.dataset.qualityLabels;
script.setAttribute('data-quality-labels', JSON.stringify(prefs.qualityLabels));
console.log('script', script.dataset);
script.textContent = `
var yttools = window.yttools || [];
console.log('script executed', yttools);
function youtubeHDListener (e) {
console.log('youtubeHDListener');
const prefs = youtubeHDListener.prefs;
const player = youtubeHDListener.player;
const log = (...args) => prefs.log === 'true' && console.log('YouTube HD::', ...args);
const log = (...args) => prefs.log === 'true' && console.log('[ythd]', ...args);
try {
if (e === 1 && player) {
Expand All @@ -67,7 +56,6 @@
'highres', 'h2880', 'hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny', 'auto'
];
const q = player.getPlaybackQuality();
console.log('≥≥≥……… prefs', prefs);
if (prefs.quality in prefs.qualityLabels) {
prefs.quality = prefs.qualityLabels[String(prefs.quality)];
}
Expand All @@ -88,12 +76,10 @@
if (prefs.higher === 'true' && compare(q, prefs.quality)) {
return log('Quality was', q, 'which is higher than ', prefs.quality, 'Changing the quality is skipped');
}
console.info('q', player.getPlaybackQuality(), 'prefs.quality', prefs.quality);
if (q === prefs.quality) {
return log('Selected quality is okay;', q);
}
const find = increase => {
console.log('≥ find', levels);
if (prefs.quality === 'highest') {
return levels[0];
}
Expand Down Expand Up @@ -121,21 +107,18 @@
}
log('Quality was', q, 'Quality is set to', nq);
}
}
catch (e) {
console.error('error', e);
log(e);
} catch (eerr) {
log(err);
}
}
youtubeHDListener.prefs = document.currentScript.dataset;
youtubeHDListener.prefs.qualityLabels = JSON.parse(document.currentScript.getAttribute('data-quality-labels') || '{}');
console.log(youtubeHDListener.prefs.qualityLabels)
yttools.push(e => {
youtubeHDListener.player = e;
youtubeHDListener(1);
e.addEventListener('onStateChange', 'youtubeHDListener');
});
// install listener
// Install listener.
function onYouTubePlayerReady (e) {
console.log('onYouTubePlayerReady', yttools);
yttools.forEach(c => {
Expand All @@ -146,9 +129,8 @@
}
});
}
// https://youtube.github.io/spfjs/documentation/events/
// See docs: https://youtube.github.io/spfjs/documentation/events/
window.addEventListener('spfready', () => {
console.log('spfready');
if (typeof window.ytplayer === 'object' && window.ytplayer.config) {
window.ytplayer.config.args.jsapicallback = 'onYouTubePlayerReady';
}
Expand Down

0 comments on commit dac2b13

Please sign in to comment.