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

能否修改一下帖子浏览页面的 TOP 链接的代码

  [复制链接]
发表于 2020-8-4 09:50:20 | 显示全部楼层 |阅读模式
帖子浏览页面 每一楼 的右下角 均有 3 个链接: 评分 报告 TOP
其中 TOP 用于将视图返回页面顶部, 现在的实现代码如下:
  1. <a href="javascript:;" onclick="scrollTo(0,0);">TOP</a>
复制代码
我对此代码在如下三种浏览器环境下测试:
Chrome 84.0.4147.105 (Official Build) (64-bit)
Firefox 76.0.1 (64 位)
IE 11.592.18362.0

仅有 IE 有正常效果返回顶部, Chrome, Firefox 均无任何响应
但如果修改一下:
  1. <a href="javascript:;" onclick="window.scrollTo(0,0);">TOP</a>
复制代码
则 3 种浏览器环境均正常响应
发表于 2020-8-4 10:54:22 | 显示全部楼层
回复 1# a20150604


   的确!希望能修改!
发表于 2020-8-4 16:04:16 | 显示全部楼层
本帖最后由 ivor 于 2020-8-4 16:13 编辑

自己优化先用着
Tampermonkey油猴脚本
  1. // ==UserScript==
  2. // @name         bathome.net-优化TOP
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        http://*.bathome.net/*
  8. // @grant        none
  9. // ==/UserScript==

  10. (function() {
  11.     var postact = document.getElementsByClassName("postact s_clear")
  12.     for(let i=1;i<postact.length;i++){
  13.         var p = postact[i].getElementsByTagName("p")[0]
  14.         var a = p.getElementsByTagName("a")
  15.         var TOP = a[a.length-1]
  16.         TOP.onclick = Function("window.scrollTo(0,0);");
  17.     }
  18. })();
复制代码

评分

参与人数 2技术 +2 收起 理由
netdzb + 1 非常厉害。
老刘1号 + 1 +1

查看全部评分

 楼主| 发表于 2020-8-4 20:22:03 | 显示全部楼层
回复 3# ivor

还有个 复制到剪贴板,  FLASH 方式很早就被现在的浏览器抛弃了
发表于 2020-8-4 21:09:01 | 显示全部楼层
这个功能greasyfork已经有了,我复制过来了方便大家用。
  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号 + 1 +1

查看全部评分

发表于 2020-8-5 18:15:13 | 显示全部楼层
回复 3# ivor


    建议发布
顺便为啥中华的代码高亮没了,emmm
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 04:33 , Processed in 0.018588 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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