返回列表 发帖

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

帖子浏览页面 每一楼 的右下角 均有 3 个链接: 评分 报告 TOP
其中 TOP 用于将视图返回页面顶部, 现在的实现代码如下:
<a href="javascript:;" onclick="scrollTo(0,0);">TOP</a>COPY
我对此代码在如下三种浏览器环境下测试:
Chrome 84.0.4147.105 (Official Build) (64-bit)
Firefox 76.0.1 (64 位)
IE 11.592.18362.0

仅有 IE 有正常效果返回顶部, Chrome, Firefox 均无任何响应
但如果修改一下:
<a href="javascript:;" onclick="window.scrollTo(0,0);">TOP</a>COPY
则 3 种浏览器环境均正常响应

回复 1# a20150604


   的确!希望能修改!

TOP

本帖最后由 ivor 于 2020-8-4 16:13 编辑

自己优化先用着
Tampermonkey油猴脚本
// ==UserScript==
// @name         bathome.net-优化TOP
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://*.bathome.net/*
// @grant        none
// ==/UserScript==
(function() {
    var postact = document.getElementsByClassName("postact s_clear")
    for(let i=1;i<postact.length;i++){
        var p = postact[i].getElementsByTagName("p")[0]
        var a = p.getElementsByTagName("a")
        var TOP = a[a.length-1]
        TOP.onclick = Function("window.scrollTo(0,0);");
    }
})();COPY
2

评分人数

#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复 3# ivor

还有个 复制到剪贴板,  FLASH 方式很早就被现在的浏览器抛弃了

TOP

这个功能greasyfork已经有了,我复制过来了方便大家用。
// ==UserScript==
// @name              replace copy flash on Discuz
// @name:zh-CN        替换Discuz的复制flash
// @description       Replace the "click here to copy" flash on Discuz
// @description:zh-CN 替换Discuz论坛的"点此复制到剪贴板"flash
// @namespace         https://github.com/Testla
// @version           0.9.1
// @include           http*://www.tsdm.me/*
// @include           http*://www.lightnovel.cn/*
// @match             http://*.bathome.net/*
// @author            Testla
// @license           MIT License
// @compatible        firefox 57 + Greasemonkey4/Tampermonkey tested
// @compatible        chrome + Tampermonkey
// @require           https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant             GM.info
// @grant             GM.setClipboard
// @grant             GM_info
// @grant             GM_setClipboard
// @grant             unsafeWindow
// ==/UserScript==
(function() {
    'use strict';
    // There are two versions available,
    // the non-privileged version doesn't use privileged API
    // but doesn't support Greasemonkey 4+
    // and may be incompatible with some old browsers
    // (check https://developer.mozilla.org/en-US/docs/Web/API/document/execCommand#Browser_compatibility).
    // To switch to the non-privileged version:
    // 1. remove all @require and @grant in the header
    // 2. add @grant none to the same place
    // 3. comment out the privileged version
    // 4. uncomment the non-privileged version
    // ---------------- BEGIN PRIVILEGED VERSION ----------------
    // If you only run on Greasemonkey 4+, you can remove the @require.
    // If you need not to run on Greasemonkey 4+,
    // you can remove the @require line together with the @grant GM.*s
    // and replace all "GM." with "GM_".
    // Note that the "@grant GM_*"s are required for Tampermonkey in Chrome
    // even if the corresponding "@grant GM.*"s and gm4-polyfill already exists,
    // please let me know if you can figure out why.
    function copyAndHint(text) {
        GM.setClipboard(text);
        // showPrompt comes with Discuz
        unsafeWindow.showPrompt(null, null, 'Copied', 3000);
    }
    function setCopy(text, hint) {
        copyAndHint(text);
    }
    function copycode(code_div) {
        copyAndHint(code_div.textContent);
    }
    var greasemonkey4OrGreater = GM.info.scriptHandler == 'Greasemonkey' &&
                                 parseFloat(GM.info.version) >= 4.0;
    if (greasemonkey4OrGreater) {
        // uses Firefox-specific hack
        // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts
        exportFunction(copyAndHint, window, {defineAs:'copyAndHint'});
        window.eval(
            'window.setCopy = function(text, hint) { copyAndHint(text); };' +
            'window.copycode = function(code_div) { copyAndHint(code_div.textContent); };');
    } else {
        unsafeWindow.setCopy = setCopy;
        unsafeWindow.copycode = copycode;
    }
    // ---------------- END PRIVILEGED VERSION ----------------
    // ---------------- BEGIN NON-PRIVILEGED VERSION ----------------
    // var copyTextarea = document.createElement("textarea");
    // copyTextarea.style.width = "0px";
    // copyTextarea.style.height = "0px";
    // copyTextarea.style.position = "fixed";
    // // https://stackoverflow.com/questions/400212
    // function copyAndHint(text) {
    //     document.body.appendChild(copyTextarea);
    //     copyTextarea.textContent = text;
    //     copyTextarea.select();
    //     try {
    //         var successful = document.execCommand('copy');
    //         var msg = successful ? 'succeeded' : 'failed';
    //         showPrompt(null, null, 'Copy ' + msg, 3000);
    //     } catch (err) {
    //         showPrompt(null, null, 'Oops, unable to copy', 3000);
    //         console.log(err);
    //     }
    //     document.body.removeChild(copyTextarea);
    // }
    // window.setCopy = function(text, hint) {
    //     copyAndHint(text);
    // };
    // window.copycode = function(code_div) {
    //     copyAndHint(code_div.textContent);
    // };
    // ---------------- END NON-PRIVILEGED VERSION ----------------
    console.log('finished replacing Discuz\'s copy flash');
})();COPY
1

评分人数

#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

回复 3# ivor


    建议发布
顺便为啥中华的代码高亮没了,emmm

TOP

返回列表