genius-date

script to inject today's date when transcribing a new song

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         genius-date
// @description  script to inject today's date when transcribing a new song
// @namespace    http://tampermonkey.net/
// @license MIT
// @version      2.0.0
// @description  A simple example userscript
// @author       solomoncyj
// @match        https://genius.com/new
// @grant        none
// ==/UserScript==

const month = ["January","February","March","April","May","June","July","August","September","October","November","December"];

var event = new Event('change');

function setNativeValue(element, value) {
    let lastValue = element.value;
    element.value = value;
    let event = new Event("input", { target: element, bubbles: true });
    // React 15
    event.simulated = true;
    // React 16
    let tracker = element._valueTracker;
    if (tracker) {
        tracker.setValue(lastValue);
    }
    element.dispatchEvent(event);
}

function inject()
{
    const today = new Date(Date.now());
  setNativeValue(document.querySelector('input[aria-label="Release Day"]'), today.getDate())
  setNativeValue(document.querySelector('input[aria-label="Release Month"]'), month[today.getMonth()])
  setNativeValue(document.querySelector('input[aria-label="Release Year"]'), today.getFullYear())



}

(function() {
   'use strict';



    let btn = document.createElement("button");
    btn.type = "button"
    btn.onclick = () => {
        inject()
    };
    const info = document.createTextNode("Today");
  var xpath = "//span[text()='Release Date']";
  var div = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    div.appendChild(btn);
    btn.appendChild(info);
})();