diff options
author | John Ankarström <john@ankarstrom.se> | 2020-10-24 19:57:00 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-10-24 19:57:24 +0200 |
commit | 47ced886fbd41a35d275526e18164aaa71202bef (patch) | |
tree | 786b8e3ce9b466cac64a1c930b00d75f065b3d50 /watch.js | |
parent | e44efcad2daf39f6b9908dd0ac46c9d1309eabcb (diff) | |
download | watch-47ced886fbd41a35d275526e18164aaa71202bef.tar.gz |
release 2.0
Diffstat (limited to 'watch.js')
-rw-r--r-- | watch.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/watch.js b/watch.js new file mode 100644 index 0000000..be0c7ef --- /dev/null +++ b/watch.js @@ -0,0 +1,42 @@ +/* This is a bookmarklet. Copy it to a bookmark in your web browser and + add javascript: in front of it. */ + +var watch = function () { + if (window.watchclicked == undefined) + window.watchclicked = 0; + if (window.watchlasttime == undefined) + window.watchlasttime = 0; + var vid = function (href) { + return 'watch:' + href.replace(/(https?:\/?\/?www\.youtube\.com\/watch.*)&list=.*$/,'$1'); + }; + var reset = function () { + window.watchclicked = 0; + Array.from(document.getElementsByTagName('a')).forEach(function (el) { + el.onclick = undefined; + el.style.cursor = el.getAttribute('data-watch-cursor-orig'); + }); + }; + var open = function (ev) { + reset(); + location.href = vid(ev.target.href); + ev.preventDefault(); + }; + var d = new Date(); + if (d.getTime() - window.watchlasttime <= 500) { /* double click */ + location.href = vid(location.href); + window.watchlasttime = d.getTime(); + return; + } + window.watchlasttime = d.getTime(); + if (window.watchclicked == 0) { + window.watchclicked = 1; + Array.from(document.getElementsByTagName('a')).forEach(function (el) { + el.onclick = open; + el.setAttribute('data-watch-cursor-orig', el.style.cursor); + el.style.setProperty('cursor', 'alias', 'important'); + }); + } else { + reset(); + } +}; +watch(); |