aboutsummaryrefslogtreecommitdiff
path: root/watch.js
diff options
context:
space:
mode:
Diffstat (limited to 'watch.js')
-rw-r--r--watch.js42
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();