-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube-add-summary-btn.user.js
55 lines (48 loc) · 2.22 KB
/
youtube-add-summary-btn.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name Add Summarize Button
// @version 2024-07-02
// @description Summarize YouTube videos using summarize.tech
// @author abstraction
// @match https://www.youtube.com/watch?v=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant GM_addStyle
// @homepageURL https://github.com/abstraction/userscripts/
// @updateURL https://github.com/abstraction/userscripts/raw/master/src/youtube-add-summary-btn.user.js
// @downloadURL https://github.com/abstraction/userscripts/raw/master/src/youtube-add-summary-btn.user.js
// ==/UserScript==
(function () {
'use strict';
const redirectUrl = `https://summarize.tech/${document.location.hostname}${document.location.pathname}${document.location.search}`;
function addButton() {
const subscribeButton = document.querySelector('#subscribe-button');
if (subscribeButton && !document.querySelector('#custom-redirect-button')) {
const button = document.createElement('button');
button.id = 'custom-redirect-button';
button.textContent = 'Summarize';
Object.assign(button.style, {
marginLeft: '8px',
padding: '0px 16px',
fontSize: '14px',
color: '#000',
backgroundColor: '#cc0000',
border: 'none',
borderRadius: '18px',
cursor: 'pointer',
height: '36px',
lineHeight: '36px',
fontWeight: 500,
fontFamily: '"Roboto","Arial",sans-serif'
});
GM_addStyle('#custom-redirect-button:hover { background-color: #b80000 !important; }');
button.onclick = () => window.location.href = redirectUrl;
subscribeButton.parentNode.insertBefore(button, subscribeButton.nextSibling);
}
}
// Try to add the button periodically in case the page content loads dynamically
// FIXME - The script is unable to insert the Summarize button at times probably
// due to the layout shift caused by YouTube's javascript. A refresh or two usually
// usually fixes it but we should determine the root cause.
const interval = setInterval(addButton, 3000);
// Clear the interval if navigating away from the page
window.addEventListener('beforeunload', () => clearInterval(interval));
})();