Hacker News new | ask | show | jobs
by somat 800 days ago
For completeness here is mine. I will try yours and see if it works better.

  // ==UserScript==
  // @name         eat my shorts
  // @namespace    http://tampermonkey.net/
  // @version      0.1
  // @description  change links to youtube shorts to reguler site
  // @author       jrs
  // @match        https://www.youtube.com/*
  // @icon         none
  // @grant        none
  // ==/UserScript==
  
  (function() {
      'use strict';
      function eat_shorts() {
          const root = document;
          const shorts_re = /^\/shorts\/(.*)/;
          const ae = root.getElementsByTagName("a");
          for (var i = 0; i < ae.length; i++) {
              const this_a = ae[i];
              const short_match = shorts_re.exec(this_a.getAttribute("href") );
              if (short_match) {
                  this_a.setAttribute("href", "/v/" + short_match[1]);
              }
          }
      }
  
      const config = {
          attributes: false,
          childList: true,
          subtree: true
      }
  
      //timer resets every time the returned function is called
      function make_reset_timer(cb, timeout) {
          var timer = setTimeout(cb, timeout);
          function reset_timer(mutation_list, observer) {
              clearTimeout(timer);
              timer = setTimeout(cb, timeout);
          }
          return reset_timer;
      }

      const short_observer = new MutationObserver(make_reset_timer(eat_shorts, 10));
      short_observer.observe(document, config);
  })();