From a8916b9308a4e2b7c1441a4d8d3c6d0b19c38fd2 Mon Sep 17 00:00:00 2001 From: zrose584 <57181548+zrose584@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:58:16 +0200 Subject: proxy 'sponsor.ajay.app' --- youtube/__init__.py | 4 ++++ youtube/static/js/common.js | 4 ---- youtube/static/js/hotkeys.js | 3 +-- youtube/static/js/sponsorblock.js | 8 ++++---- youtube/templates/base.html | 5 +++-- youtube/templates/watch.html | 1 + youtube/watch.py | 4 ++++ 7 files changed, 17 insertions(+), 12 deletions(-) (limited to 'youtube') diff --git a/youtube/__init__.py b/youtube/__init__.py index 3c271f1..92e1878 100644 --- a/youtube/__init__.py +++ b/youtube/__init__.py @@ -7,6 +7,10 @@ from sys import exc_info yt_app = flask.Flask(__name__) yt_app.config['TEMPLATES_AUTO_RELOAD'] = True yt_app.url_map.strict_slashes = False +# yt_app.jinja_env.trim_blocks = True +# yt_app.jinja_env.lstrip_blocks = True + + yt_app.add_url_rule('/settings', 'settings_page', settings.settings_page, methods=['POST', 'GET']) diff --git a/youtube/static/js/common.js b/youtube/static/js/common.js index 42fa41f..2db4390 100644 --- a/youtube/static/js/common.js +++ b/youtube/static/js/common.js @@ -108,10 +108,6 @@ function copyTextToClipboard(text) { document.body.removeChild(textArea); } -function getVideoID() { - return JSON.parse(Q(".video-info input[name=video_info_list]").value).id -} - window.addEventListener('DOMContentLoaded', function() { cur_track_idx = getDefaultTranscriptTrackIdx(); diff --git a/youtube/static/js/hotkeys.js b/youtube/static/js/hotkeys.js index 1f41510..e199f3b 100644 --- a/youtube/static/js/hotkeys.js +++ b/youtube/static/js/hotkeys.js @@ -37,9 +37,8 @@ function onKeyDown(e) { else tt.mode = "showing"; } else if (c == "t") { - let video_id = getVideoID(); let ts = Math.floor(Q("video").currentTime); - copyTextToClipboard(`https://youtu.be/${video_id}?t=${ts}`); + copyTextToClipboard(`https://youtu.be/${data.video_id}?t=${ts}`); } } diff --git a/youtube/static/js/sponsorblock.js b/youtube/static/js/sponsorblock.js index 66dcf16..692de9b 100644 --- a/youtube/static/js/sponsorblock.js +++ b/youtube/static/js/sponsorblock.js @@ -12,14 +12,14 @@ document.addEventListener('DOMContentLoaded', ()=>{ function load_sponsorblock(){ const info_elem = Q('#skip_n'); if (info_elem.innerText.length) return; // already fetched - const video_id = getVideoID(); - const hash = sha256(video_id).substr(0,4); + const hash = sha256(data.video_id).substr(0,4); const video_obj = Q("video"); - fetch(`https://sponsor.ajay.app/api/skipSegments/${hash}`) + let url = `/https://sponsor.ajay.app/api/skipSegments/${hash}`; + fetch(url) .then(response => response.json()) .then(data => { for (const video of data) { - if (video.videoID != video_id) continue; + if (video.videoID != data.video_id) continue; info_elem.innerText = `(${video.segments.length} segments)`; const cat_n = video.segments.map(e=>e.category).sort() .reduce((acc,e) => (acc[e]=(acc[e]||0)+1, acc), {}); diff --git a/youtube/templates/base.html b/youtube/templates/base.html index df7bb99..ef69960 100644 --- a/youtube/templates/base.html +++ b/youtube/templates/base.html @@ -4,8 +4,9 @@