Kaskus - Scroll to Top

Add button on Kaskus topbar to quickly scroll to top.

  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The Fuck You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://www.wtfpl.net/ for more details. */
  6.  
  7. // ==UserScript==
  8. // @id kaskus-scroll-to-top@loucypher
  9. // @name Kaskus - Scroll to Top
  10. // @namespace https://userscripts.org/users/12
  11. // @description Add button on Kaskus topbar to quickly scroll to top.
  12. // @version 1.0
  13. // @author LouCypher
  14. // @license WTFPL
  15. // @screenshot https://mediacru.sh/Qjrp3WGaeeWD.png
  16. // @icon http://loucypher.github.io/userscripts/kaskus/kaskus-48.png
  17. // @icon64URL http://loucypher.github.io/userscripts/kaskus/kaskus-64.png
  18. // @contributionURL http://loucypher.github.io/userscripts/donate.html?Kaskus+-+Scroll+to+Top
  19. // @homepageURL https://gf.qytechs.cn/scripts/3
  20. // @supportURL https://gf.qytechs.cn/scripts/3
  21. // @resource CHANGELOG https://raw.github.com/LouCypher/userscripts/master/kaskus/scroll-to-top/CHANGELOG.txt
  22. // @resource LICENSE https://raw.github.com/LouCypher/userscripts/master/licenses/WTFPL/LICENSE.txt
  23. // @include http://www.kaskus.co.id/*
  24. // @grant unsafeWindow
  25. // @grant GM_addStyle
  26. // ==/UserScript==
  27.  
  28. function $(aSelector, aNode) {
  29. return (aNode || document).querySelector(aSelector);
  30. }
  31.  
  32. function scrollToTop(aEvent) {
  33. aEvent.preventDefault();
  34. if (pageYOffset >= 1)
  35. unsafeWindow.jQuery("html").animate({scrollTop: 0}, "fast");
  36. }
  37.  
  38. function showButton() {
  39. if (pageYOffset >= header.offsetHeight)
  40. $("#scroll-to-top").className = "";
  41. else
  42. $("#scroll-to-top").className = "hide";
  43. }
  44.  
  45. var css = ".rotate-right::before{-moz-transform:rotate(90deg);"
  46. + "-webkit-transform:rotate(90deg);transform:rotate(90deg);font-size:15px;}"
  47. + "#scroll-to-top{text-align:center;width:25px;top:4px;"
  48. + (typeof opera === "object"
  49. // Opera
  50. ? "position:fixed;right:1em;background:#1484ce;"
  51. // other browsers that support CSS calc() function
  52. : "position:absolute;left:-moz-calc(50% - 12.5px);" +
  53. "left:-webkit-calc(50% - 12.5px);left:calc(50% - 12.5px);")
  54. + "}";
  55.  
  56. var header = $("#site-header .meta-header");
  57. var row = $(".row", header);
  58. if (row) {
  59. GM_addStyle(css);
  60. var link = row.insertBefore(document.createElement("a"), row.firstChild);
  61. link.id = "scroll-to-top";
  62. link.className = "hide";
  63. link.href = "#";
  64. link.rel = "tooltip";
  65. link.dataset.title = "Scroll to Top";
  66. link.dataset.placement = "bottom";
  67. link.innerHTML = '<i class="icon-step-backward header-icon rotate-right"></i>';
  68. link.addEventListener("click", scrollToTop);
  69. window.addEventListener("scroll", showButton);
  70. showButton();
  71. }

QingJ © 2025

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