Greasy Fork镜像 还支持 简体中文。

wechat add copy title&url button

try to take over the world!

  1. // ==UserScript==
  2. // @name wechat add copy title&url button
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.02
  5. // @description try to take over the world!
  6. // @author You
  7. // @include https://mp.weixin.qq.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var Start={};
  15. Start.one_create_btn = function(){
  16. var Div = document.getElementById("js_article");
  17. var button = document.createElement("input");
  18. button.setAttribute("type", "button");
  19. button.setAttribute("value", "copy_title");
  20. button.setAttribute("id", "copy_btn1");
  21. button.setAttribute("class", "class_copy_btn1");
  22.  
  23. button.style.width = "50%";
  24. button.style.height = "50px";
  25. button.style.marginLeft = "auto"
  26. button.style.marginRight = "auto"
  27.  
  28. document.body.insertBefore(button, Div);
  29.  
  30. document.getElementById("copy_btn1").onclick=function(){
  31. // IE浏览器
  32. //var clipBoardContent=document.getElementById("activity-name").innerText;
  33. //var clipBoardContent=document.title;
  34. var clipBoardContent=document.title;
  35. if (window.clipboardData) {
  36. window.clipboardData.clearData();
  37. window.clipboardData.setData("Text", clipBoardContent);
  38. alert("复制成功!");
  39. }else{
  40. if (!document.queryCommandSupported('copy')) {
  41. throw new Error('document.execCommand method not support copy command');
  42. }
  43. const input = document.createElement('input'); // 要input类型
  44. //input.style.cssText = 'display: block;opacity: 0;position: absolute;left: -10000px;top: -10000px;z-index: -1;width: 1px;height: 1px;'
  45. document.body.appendChild(input);
  46. input.value = clipBoardContent;
  47. input.select();
  48. document.execCommand('copy');
  49. document.body.removeChild(input);
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56. // Error 不能通过这种属性和值的方式建立关联
  57. /*
  58. button.setAttribute("onclick", "copyUrl()");
  59. function copyUrl()
  60. {
  61. alert("复制成功!");
  62. }
  63. */
  64.  
  65. };
  66. Start.two_create_btn = function(){
  67. var Div = document.getElementById("js_article");
  68. var button = document.createElement("input");
  69. button.setAttribute("type", "button");
  70. button.setAttribute("value", "copy_url");
  71. button.setAttribute("id", "copy_btn2");
  72. button.setAttribute("class", "class_copy_btn1");
  73.  
  74. button.style.width = "50%";
  75. button.style.height = "50px";
  76. button.style.marginLeft = "auto"
  77. button.style.marginRight = "auto"
  78.  
  79. document.body.insertBefore(button, Div);
  80.  
  81. document.getElementById("copy_btn2").onclick=function(){
  82. // IE浏览器
  83. //var clipBoardContent=document.getElementById("activity-name").innerText;
  84. //var clipBoardContent=document.title;
  85. var clipBoardContent=document.querySelector("head > meta:nth-child(14)").content;
  86. if (window.clipboardData) {
  87. window.clipboardData.clearData();
  88. window.clipboardData.setData("Text", clipBoardContent);
  89. alert("复制成功!");
  90. }else{
  91. if (!document.queryCommandSupported('copy')) {
  92. throw new Error('document.execCommand method not support copy command');
  93. }
  94. const input = document.createElement('input'); // 要input类型
  95. //input.style.cssText = 'display: block;opacity: 0;position: absolute;left: -10000px;top: -10000px;z-index: -1;width: 1px;height: 1px;'
  96. document.body.appendChild(input);
  97. input.value = clipBoardContent;
  98. input.select();
  99. document.execCommand('copy');
  100. document.body.removeChild(input);
  101. }
  102.  
  103.  
  104.  
  105. }
  106. }
  107. Start.one_create_btn();
  108. Start.two_create_btn();
  109.  
  110.  
  111.  
  112. })();
  113.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址