找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 13166|回复: 9

我们站的代码没法直接复制

  [复制链接]
发表于 2023-2-18 21:37:03 | 显示全部楼层 |阅读模式
现在复制
  1. 直接复制
  2. |
  3. \ /
复制代码
需要安装flash
但是很多人的电脑上已经没有flash了
一个innertext为什么还要flash呢?搞不明白
现在还得手动刷黑ctrl+c
 楼主| 发表于 2023-2-18 21:41:15 | 显示全部楼层
直接getelementbyid("code0").innertext不就行了?
 楼主| 发表于 2023-2-18 21:42:44 | 显示全部楼层
我看源代码里有个copycode函数,难道是这里用了flash?
我们吧也没什么动画,就算有也不用用flash老古董吧
发表于 2023-2-19 19:16:21 | 显示全部楼层
回复 1# jyswjjgdwtdtj
承认,我还以为就我无法复制
发表于 2023-2-19 19:30:33 | 显示全部楼层
  1. // ==UserScript==
  2. // @name              replace copy flash on Discuz
  3. // @name:zh-CN        替换Discuz的复制flash
  4. // @description       Replace the "click here to copy" flash on Discuz
  5. // @description:zh-CN 替换Discuz论坛的"点此复制到剪贴板"flash
  6. // @namespace         https://github.com/Testla
  7. // @version           0.9.1
  8. // @include           http*://www.tsdm.me/*
  9. // @include           http*://www.lightnovel.cn/*
  10. // @match             http://*.bathome.net/*
  11. // @author            Testla
  12. // @license           MIT License
  13. // @compatible        firefox 57 + Greasemonkey4/Tampermonkey tested
  14. // @compatible        chrome + Tampermonkey
  15. // @require           https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  16. // @grant             GM.info
  17. // @grant             GM.setClipboard
  18. // @grant             GM_info
  19. // @grant             GM_setClipboard
  20. // @grant             unsafeWindow
  21. // ==/UserScript==

  22. (function() {
  23.     'use strict';

  24.     // There are two versions available,
  25.     // the non-privileged version doesn't use privileged API
  26.     // but doesn't support Greasemonkey 4+
  27.     // and may be incompatible with some old browsers
  28.     // (check https://developer.mozilla.org/en-US/docs/Web/API/document/execCommand#Browser_compatibility).
  29.     // To switch to the non-privileged version:
  30.     // 1. remove all @require and @grant in the header
  31.     // 2. add @grant none to the same place
  32.     // 3. comment out the privileged version
  33.     // 4. uncomment the non-privileged version

  34.     // ---------------- BEGIN PRIVILEGED VERSION ----------------
  35.     // If you only run on Greasemonkey 4+, you can remove the @require.
  36.     // If you need not to run on Greasemonkey 4+,
  37.     // you can remove the @require line together with the @grant GM.*s
  38.     // and replace all "GM." with "GM_".
  39.     // Note that the "@grant GM_*"s are required for Tampermonkey in Chrome
  40.     // even if the corresponding "@grant GM.*"s and gm4-polyfill already exists,
  41.     // please let me know if you can figure out why.

  42.     function copyAndHint(text) {
  43.         GM.setClipboard(text);
  44.         // showPrompt comes with Discuz
  45.         unsafeWindow.showPrompt(null, null, 'Copied', 3000);
  46.     }

  47.     function setCopy(text, hint) {
  48.         copyAndHint(text);
  49.     }

  50.     function copycode(code_div) {
  51.         copyAndHint(code_div.textContent);
  52.     }

  53.     var greasemonkey4OrGreater = GM.info.scriptHandler == 'Greasemonkey' &&
  54.                                  parseFloat(GM.info.version) >= 4.0;
  55.     if (greasemonkey4OrGreater) {
  56.         // uses Firefox-specific hack
  57.         // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts
  58.         exportFunction(copyAndHint, window, {defineAs:'copyAndHint'});
  59.         window.eval(
  60.             'window.setCopy = function(text, hint) { copyAndHint(text); };' +
  61.             'window.copycode = function(code_div) { copyAndHint(code_div.textContent); };');
  62.     } else {
  63.         unsafeWindow.setCopy = setCopy;
  64.         unsafeWindow.copycode = copycode;
  65.     }
  66.     // ---------------- END PRIVILEGED VERSION ----------------

  67.     // ---------------- BEGIN NON-PRIVILEGED VERSION ----------------
  68.     // var copyTextarea = document.createElement("textarea");
  69.     // copyTextarea.style.width = "0px";
  70.     // copyTextarea.style.height = "0px";
  71.     // copyTextarea.style.position = "fixed";

  72.     // // https://stackoverflow.com/questions/400212
  73.     // function copyAndHint(text) {
  74.     //     document.body.appendChild(copyTextarea);
  75.     //     copyTextarea.textContent = text;
  76.     //     copyTextarea.select();

  77.     //     try {
  78.     //         var successful = document.execCommand('copy');
  79.     //         var msg = successful ? 'succeeded' : 'failed';
  80.     //         showPrompt(null, null, 'Copy ' + msg, 3000);
  81.     //     } catch (err) {
  82.     //         showPrompt(null, null, 'Oops, unable to copy', 3000);
  83.     //         console.log(err);
  84.     //     }
  85.     //     document.body.removeChild(copyTextarea);
  86.     // }

  87.     // window.setCopy = function(text, hint) {
  88.     //     copyAndHint(text);
  89.     // };

  90.     // window.copycode = function(code_div) {
  91.     //     copyAndHint(code_div.textContent);
  92.     // };
  93.     // ---------------- END NON-PRIVILEGED VERSION ----------------

  94.     console.log('finished replacing Discuz\'s copy flash');
  95. })();
复制代码

评分

参与人数 1技术 +1 收起 理由
我号被盗了 + 1 失踪人口回归

查看全部评分

 楼主| 发表于 2023-2-19 21:31:02 | 显示全部楼层
回复 5# 老刘1号


所以为啥要用flash啊
发表于 2023-2-19 22:46:11 | 显示全部楼层
回复 6# jyswjjgdwtdtj


    这你得问batcher了,不是我的锅()
之前我也建议过给论坛加高亮、markdown、换掉flash啥的,都石沉大海了
这个站目前依然对ie6兼容()
 楼主| 发表于 2023-2-20 18:39:46 | 显示全部楼层
回复 7# 老刘1号


    嘿 ie马上就要被微软灭掉了
发表于 2023-2-22 09:37:55 | 显示全部楼层
回复 1# jyswjjgdwtdtj


感谢对论坛的关心和建议。
目前论坛运行以稳为主,除了影响发帖、回帖等核心功能的情况,其他方面暂时不计划做调整。

有兴趣的朋友们可以试试:油猴脚本解决代码无法复制、TOP按钮不管用、代码高亮
http://bbs.bathome.net/thread-65254-1-1.html
发表于 2025-12-4 19:15:31 | 显示全部楼层
已修复(请使用现代浏览器浏览论坛)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 07:07 , Processed in 0.029346 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表