thwiki.cc Lyrics Reader

A script that makes easier to get lyrics from Chinese Touhou Wiki pages.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name     thwiki.cc Lyrics Reader
// @name:en     Lyrics Reader on Chinese Touhou Wiki
// @namespace https://takkkane.tumblr.com/scripts/lyricsReaderChinese
// @supportURL     https://twitter.com/TaxDelusion
// @description A script that makes easier to get lyrics from Chinese Touhou Wiki pages.
// @version  0.1.1
// @include  https://thwiki.cc/*
// @require  https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require  https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.min.js
// @grant    none
// ==/UserScript==


$(document).ready(function () {

  //they're just in a row above the first lyrics row
	var lyricsHeaders = $("body").find(".tt-lyrics-header > td.tt-mainh, td.tt-tranh");

	lyricsHeaders.each(function (index, header) {

		var onClickHandler = function () {

			var lyrics = "";
      var line = "";
      var lineSeparator = '\r';
			$("body").find("tr.tt-main-ja, tr.tt-main-en, tr.tt-lyrics-sep").find("td:nth-child(" + (index + 2) + ")").each(function (i, e) {
        
        line = e.textContent.trim();
        lyrics += (line + lineSeparator);
			});

      lyrics = lyrics.trim();
			utils.copyToClipboard(lyrics, header);
			
		};

		$(header).on("click", onClickHandler);
    $(header).append("<span style='color:navy; color-background:white'>&#x2139;</span>");

	});

});


// ----- utils

var utils = {
	copyToClipboard: function (data, domElement) {
		var textArea = document.createElement("textarea");
		textArea.value = data;
		domElement.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);
      $.notify('Copying lyrics was ' + msg + '!', {'position': 'top center', 'className': successful ? 'success' : 'error'});
		} catch (err) {
			console.error('Fallback: Oops, unable to copy', err);
		}

		domElement.removeChild(textArea);
	}
};

console.log("Loading done!");