wechat add copy title&url button

try to take over the world!

2020-11-26 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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();



})();