wechat add copy title&url button

try to take over the world!

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         wechat add copy title&url button
// @namespace    http://tampermonkey.net/
// @version      0.02
// @description  try to take over the world!
// @author       You
// @include      https://mp.weixin.qq.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var Start={};
    Start.one_create_btn = function(){
        var Div = document.getElementById("js_article");
        var button = document.createElement("input");
        button.setAttribute("type", "button");
        button.setAttribute("value", "copy_title");
        button.setAttribute("id", "copy_btn1");
        button.setAttribute("class", "class_copy_btn1");

        button.style.width = "50%";
        button.style.height = "50px";
        button.style.marginLeft = "auto"
        button.style.marginRight = "auto"

        document.body.insertBefore(button, Div);

        document.getElementById("copy_btn1").onclick=function(){
            // IE浏览器
            //var clipBoardContent=document.getElementById("activity-name").innerText;
            //var clipBoardContent=document.title;
            var clipBoardContent=document.title;
            if (window.clipboardData) {
                window.clipboardData.clearData();
                window.clipboardData.setData("Text", clipBoardContent);
                alert("复制成功!");
            }else{
                if (!document.queryCommandSupported('copy')) {
                    throw new Error('document.execCommand method not support copy command');
                }
                const input = document.createElement('input'); // 要input类型
                //input.style.cssText = 'display: block;opacity: 0;position: absolute;left: -10000px;top: -10000px;z-index: -1;width: 1px;height: 1px;'
                document.body.appendChild(input);
                input.value = clipBoardContent;
                input.select();
                document.execCommand('copy');
                document.body.removeChild(input);
            }



        }

        // Error 不能通过这种属性和值的方式建立关联
        /*
        button.setAttribute("onclick", "copyUrl()");
        function copyUrl()
        {
            alert("复制成功!");
        }
        */

    };
    Start.two_create_btn = function(){
        var Div = document.getElementById("js_article");
        var button = document.createElement("input");
        button.setAttribute("type", "button");
        button.setAttribute("value", "copy_url");
        button.setAttribute("id", "copy_btn2");
        button.setAttribute("class", "class_copy_btn1");

        button.style.width = "50%";
        button.style.height = "50px";
        button.style.marginLeft = "auto"
        button.style.marginRight = "auto"

        document.body.insertBefore(button, Div);

        document.getElementById("copy_btn2").onclick=function(){
            // IE浏览器
            //var clipBoardContent=document.getElementById("activity-name").innerText;
            //var clipBoardContent=document.title;
            var clipBoardContent=document.querySelector("head > meta:nth-child(14)").content;
            if (window.clipboardData) {
                window.clipboardData.clearData();
                window.clipboardData.setData("Text", clipBoardContent);
                alert("复制成功!");
            }else{
                if (!document.queryCommandSupported('copy')) {
                    throw new Error('document.execCommand method not support copy command');
                }
                const input = document.createElement('input'); // 要input类型
                //input.style.cssText = 'display: block;opacity: 0;position: absolute;left: -10000px;top: -10000px;z-index: -1;width: 1px;height: 1px;'
                document.body.appendChild(input);
                input.value = clipBoardContent;
                input.select();
                document.execCommand('copy');
                document.body.removeChild(input);
            }



        }
    }
    Start.one_create_btn();
    Start.two_create_btn();



})();