// ==UserScript==
// @name         pinboard-youtube-alternates
// @version      1.0.1
// @description  Adds alternative links to YouTube videos on Pinboard.in
// @namespace    http://kafene.org
// @match        *://*.pinboard.in/*
// @run-at       document-start
// @grant        none
// @license      MIT <https://raw.githubusercontent.com/kafene/userscripts/mater/LICENSE>
// @require      https://raw.githubusercontent.com/ded/domready/master/src/ready.js
// @downloadURL  https://raw.githubusercontent.com/kafene/userscripts/master/pinboard-youtube-alternates.user.js
// @updateURL    https://raw.githubusercontent.com/kafene/userscripts/master/pinboard-youtube-alternates.user.js
// ==/UserScript==

domready(function () {
    var links = document.querySelectorAll('a.bookmark_title[href^="https://www.youtube.com/watch"]');
    var regex = /[?&]v=([^#&]+)/;

    [].forEach.call(links, function (a) {
        var v = regex.exec(a.href);
        if (!v || !v[1]) { return; }

        var description = a.parentNode.querySelector('.description');
        if (!description) {
            description = document.createElement('div');
            description.className = 'description';
            a.parentNode.insertBefore(description, a.nextSibling);
        }

        description.insertAdjacentHTML('AFTERBEGIN',
            '<p>Watch with: ' +
            '<a href="http://fixyt.com/watch?v=' + v[1] + '" target="_blank">fixYT</a> &#8214; ' +
            '<a href="http://toogl.es/#/view/' + v[1] + '" target="_blank">Toogles</a> &#8214; ' +
            '<a href="http://tube.majestyc.net/?v=' + v[1] + '" target="_blank">Accessible Interface to YouTube</a>' +
            '</p>'
        );
    });
});

@@ -77,17 +77,17 @@
     1.0.
-1
+2
 %0A// @des
@@ -763,17 +763,17 @@
 ctorAll(
-'
+%22
 a.bookma
@@ -787,17 +787,17 @@
 e%5Bhref%5E=
-%22
+'
 https://
@@ -821,11 +821,11 @@
 atch
-%22%5D'
+'%5D%22
 );%0A 
@@ -831,17 +831,31 @@
     var 
-r
+youtubeVideoIdR
 egex = /
@@ -909,17 +909,20 @@
 nction (
-a
+link
 ) %7B%0A    
@@ -933,13 +933,33 @@
 var 
-v = r
+matches = youtubeVideoIdR
 egex
@@ -964,17 +964,20 @@
 ex.exec(
-a
+link
 .href);%0A
@@ -993,31 +993,77 @@
 f (!
-v %7C%7C !v%5B1%5D) %7B return; %7D
+matches %7C%7C !matches%5B1%5D) %7B return; %7D%0A        var videoId = matches%5B1%5D;
 %0A%0A  
@@ -1086,17 +1086,20 @@
 ption = 
-a
+link
 .parentN
@@ -1281,17 +1281,20 @@
         
-a
+link
 .parentN
@@ -1323,17 +1323,20 @@
 iption, 
-a
+link
 .nextSib
@@ -1392,17 +1392,17 @@
 entHTML(
-'
+%22
 AFTERBEG
@@ -1403,17 +1403,17 @@
 TERBEGIN
-'
+%22
 ,%0A      
@@ -1422,11 +1422,40 @@
     
-'
+%22
 %3Cp
+ class='youtube-alternatives'
 %3EWat
@@ -1465,11 +1465,13 @@
 with
-: '
+... %22
  +%0A 
@@ -1477,33 +1477,33 @@
             
-'
+%22
 %3Ca href=
 %22http://fixy
@@ -1486,25 +1486,25 @@
    %22%3Ca href=
-%22
+'
 http://fixyt
@@ -1520,37 +1520,24 @@
 h?v=
-'
+%22
  + v
-%5B1%5D + '%22 target=%22_blank%22
+ideoId + %22'
 %3Efix
@@ -1543,33 +1543,33 @@
 xYT%3C/a%3E &#8214; 
-'
+%22
  +%0A            '
@@ -1563,33 +1563,33 @@
             
-'
+%22
 %3Ca href=
 %22http://toog
@@ -1568,33 +1568,33 @@
        %22%3Ca href=
-%22
+'
 http://toogl.es/
@@ -1604,45 +1604,237 @@
 iew/
-' + v%5B1%5D + '%22 target=%22_blank%22%3EToogles
+%22 + videoId + %22'%3EToogles%3C/a%3E &#8214; %22 +%0A            %22%3Ca href='http://viewpure.com/%22 + videoId + %22'%3EViewPure%3C/a%3E &#8214; %22 +%0A            %22%3Ca href='http://quietube.com/v.php/http://www.youtube.com/watch?v=%22 + videoId + %22'%3Equietube
 %3C/a%3E
@@ -1842,17 +1842,17 @@
 &#8214; 
-'
+%22
  +%0A     
@@ -1862,17 +1862,17 @@
     
-'
+%22
 %3Ca href=
 %22htt
@@ -1867,17 +1867,17 @@
 %3Ca href=
-%22
+'
 http://t
@@ -1900,37 +1900,24 @@
 /?v=
-'
+%22
  + v
-%5B1%5D + '%22 target=%22_blank%22
+ideoId + %22'
 %3EAcc
@@ -1948,17 +1948,17 @@
 Tube%3C/a%3E
-'
+%22
  +%0A     
@@ -1968,23 +1968,14 @@
     
-'
+%22
 %3C/p%3E
-'%0A        
+%22
 );%0A 

add viewpure and quietube