MXM Lyrics Copier

Shift + C to copy the text lyrics on MXM website by frontend (Only the original version, translation not supported)

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         MXM Lyrics Copier
// @version      0.1
// @description  Shift + C to copy the text lyrics on MXM website by frontend (Only the original version, translation not supported)
// @author       XMAnon
// @match        https://www.musixmatch.com/*
// @grant        none
// @namespace https://greasyfork.org/users/666548
// ==/UserScript==

(function() {
    'use strict';
    function copyToClipboard(text) {
        if (window.clipboardData && window.clipboardData.setData) {
            // IE specific code path to prevent textarea being shown while dialog is visible.
            return clipboardData.setData("Text", text);

        } else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
            var textarea = document.createElement("textarea");
            textarea.textContent = text;
            textarea.style.position = "fixed";// Prevent scrolling to bottom of page in MS Edge.
            document.body.appendChild(textarea);
            textarea.select();
            try {
                return document.execCommand("copy");// Security exception may be thrown by some browsers.
            } catch (ex) {
                console.warn("Copy to clipboard failed.", ex);
                return false;
            } finally {
                document.body.removeChild(textarea);
            }
        }
    }
    function getMXM(){
        var textLyricNodes = document.querySelectorAll("#site .mxm-lyrics__content");
        if (!textLyricNodes) {
                console.warn("lyric not found");
                return;}
        var lyricBlock = textLyricNodes.length;
        var textLyric ='';
        for(var i =0;i<lyricBlock;i++){
            textLyric = textLyric + '\n' + textLyricNodes[i].innerText;
        }
            copyToClipboard(textLyric);
            console.log(textLyric);
    }
    document.onkeydown = function(oEvent) {//Shift + C to trigger event
        oEvent = oEvent || window.oEvent;
        //get keyCode value
        var nKeyCode = oEvent.keyCode // || oEvent.which || oEvent.charCode;
        //get "shift" event property
        var bShiftKeyCode = oEvent.shiftKey //|| oEvent.metaKey;
        if(nKeyCode == 67 && bShiftKeyCode) {//shift + c :  shift(shiftKey) c(keyCode = 67; which = 67; charCode = 0 ) x(keyCode = 88;which = 88; charCode = 0 )
            //doSomeThing...
            //alert('you punched shift + c');
            getMXM();
        }
    }
})();