DegradachWiki QoL

Небольшой QoL скрипт для ДеградачВики

当前为 2023-04-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         DegradachWiki QoL
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Небольшой QoL скрипт для ДеградачВики
// @author       Inoix
// @match        https://www.youtube.com/watch*
// @icon         https://static.miraheze.org/degrabebswiki/a/a4/Faviconchik.png
// @grant        none
// @license MIT
// ==/UserScript==
function fallbackCopyTextToClipboard(text) {
  var textArea = document.createElement("textarea");
  textArea.value = text;

  // Avoid scrolling to bottom
  textArea.style.top = "0";
  textArea.style.left = "0";
  textArea.style.position = "fixed";

  document.body.appendChild(textArea);
  textArea.focus();
  textArea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Fallback: Copying text command was ' + msg);
  } catch (err) {
    console.error('Fallback: Oops, unable to copy', err);
  }

  document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
  if (!navigator.clipboard) {
    fallbackCopyTextToClipboard(text);
    return;
  }
  navigator.clipboard.writeText(text).then(function() {
    console.log('Async: Copying to clipboard was successful!');
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
}
(function() {
    'use strict';
    document.onkeypress = function (e) {
        var exceptKey = "NumpadDecimal";
        e = e || window.event;

        if (e.code != exceptKey) {return};

        var timeclass = "ytp-time-current";
        var timeElement = document.getElementsByClassName(timeclass);
        var text = timeElement[0].textContent;
        var timeraw = text.split(":");
        timeraw.reverse();

        var timereal = 0;
        var cur = 1;
        for (var time of timeraw) {
            timereal = timereal + Number(time)*cur;
            cur = cur * 60;
        };
        console.log(timereal);
        var current_url = window.location.href;

        var slice_id = current_url.indexOf("&t=");
        if (slice_id !== -1) {
            current_url = current_url.slice(0,slice_id);
        };
        var new_url = current_url + "&t=" + timereal + "s"

        copyTextToClipboard(new_url);
    };
    // Your code here...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址