Skip to content

Instantly share code, notes, and snippets.

@Tazeki
Last active August 1, 2019 11:45
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Tazeki/4474bc972710872c429e660a6b08681d to your computer and use it in GitHub Desktop.
Save Tazeki/4474bc972710872c429e660a6b08681d to your computer and use it in GitHub Desktop.
YouTube / HookTube RegEx based URL conversion.
// ==UserScript==
// @name URL Conversion | YouTube - HookTube
// @namespace Tazeki
// @description The smallest, possibly most useful YouTube-HookTube conversion script. RegEx based. Report bugs to tangentale@protonmail.com. Sends any /www.youtube.com/ sites to HookTube before page load. Does not affect /other.youtube.com/, (gaming.youtube.com, creatoracademy.youtube.com, etc.).
// @include *youtube*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
var url = window.location.toString();
if (url.indexOf('www.youtube.com') !== - 1) {
window.location = url.replace(/youtube.com/, 'hooktube.com');
} else if (url.indexOf('www.youtu.be') !== - 1) {
window.location = url.replace(/youtu.be/, 'hooktube.com');
}
@atonn
Copy link

atonn commented Jan 7, 2018

This is one possibility to add youtu.be: https://gist.github.com/atonn/551d2846ee0055c3b7c45a001d2376b5

Unfortunately, my Chrome still sends out a request to youtube before redirecting, not sure if it's possible to prevent this via a userscript or only with a Chrome Extension

@Tazeki
Copy link
Author

Tazeki commented Jan 26, 2018

@atonn : Took your suggestion, basically just copied your code.
This script isn't preventing your browser from sending a request, but it runs before the page loads. Perhaps there is a way to get around this, but I'm not a professional web dev; I don't know how. I might look into it at some point.

Cheers,
Taz

@Zero3K
Copy link

Zero3K commented Jan 28, 2018

It would be nice if it could replace embedded Youtube videos with embedded Hooktube videos.

@Zero3K
Copy link

Zero3K commented Jan 28, 2018

Oh wait, it already does. I think that it should be made to disable autoplay on embedded youtube videos.

@Tazeki
Copy link
Author

Tazeki commented Feb 7, 2018

With Firefox, go to about:config and toggle media.autoplay.enabled to false.
I found this code for other browsers, but I haven't checked it through:


// @name Pause all HTML5 videos on load

// @author Scuzzball

// @namespace http://userscripts.org/users/Scuzzball

// @description Pause autoplaying HTML5 videos on load. In Firefox just go into about:config and look for media.autoplay.enabled and set to false.

// @version 1

// @include http://www.youtube.com

// @include http://youtube.com

// ==/UserScript==

function stopVideo(){for(var e=0;e<videos.length;e++)videos[e].pause(),video.currentTime=0}function f(){try{var e=document.getElementById("autoplay-checkbox").parentNode.parentNode;"checkbox-on-off"==e.className&&e.parentNode.removeChild(e)}catch(o){}}var videos=document.getElementsByTagName("video");window.addEventListener("load",stopVideo,!1),f(),document.body.addEventListener("DOMSubtreeModified",f,!1);

Cheers,
Taz.

@OdinGitDat
Copy link

Could you make an exception in the script for youtube pages that do not contain any videos? Right now when I try to visit my subscription page (http://www.youtube.com/feed/subscriptions/u) I am redirected to a hooktube page that doesn't exist. It would be nice if I could still do that.

@Vishukani
Copy link

Vishukani commented May 19, 2018

Here are my versions, I use them with Adguard for Windows as a user filter rule so they're one-liners:
1- simple version
checks for watch and v=
code:
(function(){var a="hooktube.com",b=window.location.href;(function(){"use strict";var a=window.location.href;if(-1<a.indexOf("youtube.com")&&-1<a.indexOf("v=")&&-1<a.indexOf("watch")){window.location.href=a.replace("youtube.com","hooktube.com")}})();
2- my personal version:

  • I don't like polymer UI of Youtube ,
    so, I add disable_polymer=true
  • I don't like localized youtube (I don't login to youtube, and I reject cookies too)
    so, I add hl=en&gl=US
  • if watch parameter matches, there'll be a confirmation dialog asking to go to hooktube or stay.

code:
window.onload=(function(){"use strict";var a=function(){this.addr=window.location.href};a.prototype.has=function(d){return-1<this.addr.indexOf(d)},a.prototype.rp=function(){return this.addr=this.addr.replace("youtube.com","hooktube.com"),this},a.prototype.fixyt=function(){var d="hl=en&gl=US&disable_polymer=true";return this.addr=-1<this.addr.indexOf("?")?this.addr+"&"+d:this.addr+"?"+d,this},a.prototype.go=function(){window.location.href=this.addr};var b=new a;if(b.has("youtube.com")){var c=!b.has("disable_polymer");b.has("watch")&&c?confirm("go to hooktube?")?b.rp().go():c&&b.fixyt().go():c&&b.fixyt().go()}})();

@Vishukani
Copy link

Vishukani commented May 20, 2018

Here comes my personal version as a user script with config options, you can state which url parts to redirect, confirm option, polymer, global etc ;

// ==UserScript==
// @name         Yooktube
// @namespace    http://localhost/
// @version      0.1
// @description  Your Script
// @author       nobody
// @match        http*://*.youtube.com/*
// @runat        document-start
// @grant        none
// ==/UserScript==

(function() {
  "use strict";

  //do you want to disable_polymer UI?

  var no_polymer = 1;
  //do you want to force global content with US English?
  var global_tube = 1;
  //which URL parts to trigger a redirect to hooktube?
  var redirparts = ["watch", "channel"];
  //should ask for confirm before redirect?
  var askconfirm = 1;

  var np = "disable_polymer=true";
  var gt = "hl=en&gl=US";
  var tube = function htube() {
    this.addr = window.location.href;
  };
  tube.prototype.has = function(y) {
    if (Array.isArray(y)) {
      for (var i = 0; i < y.length; i++) {
        if (this.addr.indexOf(y[i]) > -1) return true;
      }
    } else {
      return this.addr.indexOf(y) > -1;
    }
    return false;
  };
  tube.prototype.rp = function() {
    var ht = "hooktube.com";
    this.addr = this.addr.replace("youtube.com", ht);
    return this;
  };
   tube.prototype.fixyt = function() {
    var permitted = no_polymer + global_tube;
    if (permitted > 0) {
      var merger = permitted > 1 ? "&" : "";
      var str = ((global_tube)? gt : "")  + merger + ((no_polymer)? np : "");
       var symb=(this.addr.indexOf("?") > -1) ? "&" : "?";
        this.addr+= symb + str;
    }
    return this;
  };
  tube.prototype.go = function() {
    window.location.href = this.addr;
  };
  var url = new tube();
  var needfix = true;
  var needredir = false;
  if (url.has("youtube.com")) {
    if ((url.has(np) && no_polymer) || (url.has(gt) && global_tube)) needfix = false;
      if (url.has(redirparts) && needfix) needredir = true;
    if (needredir) {
      if (askconfirm) {
        if (confirm("go to hooktube?")) {
          url.rp().go();
        } else {
          if (needfix) {
            url.fixyt().go();
          }
        }
      } else {
        url.rp().go();
      }
    } else {
      if (needfix) {
        url.fixyt().go();
      }
    }
  }
})();

@Lew-Rockwell-Fan
Copy link

Lew-Rockwell-Fan commented May 25, 2018

Are there instructions somewhere on how to use this? I suggest it would probably be a good thing. I bumbled around and made it work. Maybe this will some other poor, clueless person:

I'm using Pale Moon. I installed Guerilla Scripting (NOT mispelled) from here:
http://addons.palemoon.org/addon/guerilla-scripting/
Firefox users would probably find Grease Monkey would work the same way. Just guessing.

Then , after studying the content, I downloaded the raw file from here

to this directory:
/home/MY-USER-NAME/.moonchild productions/pale moon/MY-PROFILE-DIRECTORY-NAME/guerrillas/scripts

Firefox users will need to look up how to find their profile directory and maybe read a how to on Grease Monkey .
Works great.

@LOuroboros
Copy link

LOuroboros commented Jul 25, 2018

Firefox users will need to look up how to find their profile directory and maybe read a how to on Grease Monkey .

Not at all, @Lew-Rockwell-Fan. Even someone like me, who only had one single script installed was able to do it just fine.

  1. Copy the piece of code created by Tazeki
  2. Go to GreaseMonkey and hit the "New User Script" button.
  3. In the new tab that opens, paste the code and hit the floppy disk/save button
  4. Test.

And that's it. It's extremely easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment