ST-Script

修改google背景图、去除页脚;CSDN自动阅读全文、关闭页脚登录注册框。

目前为 2018-06-15 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name ST-Script
  3. // @namespace https://www.saintic.com/
  4. // @version 0.2
  5. // @description 修改google背景图、去除页脚;CSDN自动阅读全文、关闭页脚登录注册框。
  6. // @author staugur
  7. // @match *://www.google.com/*
  8. // @match *://www.google.co.*/*
  9. // @match http*://blog.csdn.net/*/article/details/*
  10. // @grant none
  11. // @github https://github.com/staugur/scripts/blob/master/userscripts/ST-Script.user.js
  12. // @supportURL https://github.com/staugur/scripts/issues
  13. // @license MIT
  14. // @date 2018-04-27
  15. // @modified 2018-06-15
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. //配置
  21. var conf = {
  22. google: {
  23. //此项设置是否开启修改google背景图功能
  24. enable: true,
  25. //此项设置是背景图地址,当上述项为true时有效
  26. bgUrl: "https://open.saintic.com/api/bingPic/",
  27. //此项设置隐藏google首页底部页脚
  28. hiddenFooter: true
  29. },
  30. csdn: {
  31. //此项设置自动展开全文
  32. auto_read_full: true,
  33. //此项设置关闭登录注册弹框
  34. auto_close_loginbox: true,
  35. //此项设置关闭左侧底部广告
  36. auto_remove_asidefooter: true
  37. }
  38. };
  39. //公共接口
  40. var api = {
  41. getDomain: function() {
  42. return document.domain;
  43. },
  44. getUrlRelativePath: function() {
  45. var url = document.location.toString();
  46. var arrUrl = url.split("//");
  47. var start = arrUrl[1].indexOf("/");
  48. var relUrl = arrUrl[1].substring(start); //stop省略,截取从start开始到结尾的所有字符
  49. if (relUrl.indexOf("?") != -1) {
  50. relUrl = relUrl.split("?")[0];
  51. }
  52. return relUrl;
  53. },
  54. getUrlQuery: function(key, acq) {
  55. /*
  56. 获取URL中?之后的查询参数,不包含锚部分,比如url为http://passport.saintic.com/user/message/?status=1&Action=getCount
  57. 若无查询的key,则返回整个查询参数对象,即返回{status: "1", Action: "getCount"};
  58. 若有查询的key,则返回对象值,返回值可以指定默认值acq:如key=status, 返回1;key=test返回acq
  59. */
  60. var str = location.search;
  61. var obj = {};
  62. if (str) {
  63. str = str.substring(1, str.length);
  64. // 以&分隔字符串,获得类似name=xiaoli这样的元素数组
  65. var arr = str.split("&");
  66. //var obj = new Object();
  67. // 将每一个数组元素以=分隔并赋给obj对象
  68. for (var i = 0; i < arr.length; i++) {
  69. var tmp_arr = arr[i].split("=");
  70. obj[decodeURIComponent(tmp_arr[0])] = decodeURIComponent(tmp_arr[1]);
  71. }
  72. }
  73. return key ? obj[key] || acq : obj;
  74. },
  75. isContains: function(str, substr) {
  76. /* 判断str中是否包含substr */
  77. return str.indexOf(substr) >= 0;
  78. },
  79. arrayContains: function(arr, obj) {
  80. var i = arr.length;
  81. while (i--) {
  82. if (arr[i] === obj) {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. };
  89. //给Google™ 搜索页设置个背景图片、隐藏页脚
  90. if (conf.google.enable === true) {
  91. if (api.isContains(api.getDomain(), "www.google.co") && api.arrayContains(["/", "/webhp"], api.getUrlRelativePath())) {
  92. //设置body背景颜色、图片、重复性、起始位置
  93. document.body.style.backgroundColor = "inherit";
  94. document.body.style.backgroundImage = "url('" + conf.google.bgUrl + "')";
  95. document.body.style.backgroundRepeat = "no-repeat";
  96. document.body.style.backgroundPosition = "50% 50%";
  97. //隐藏页脚
  98. if (conf.google.hiddenFooter === true) {
  99. document.getElementById('footer').style.display = 'none';
  100. }
  101. }
  102. }
  103. //CSDN文章详情页自动展开全文并去除阅读更多按钮
  104. if (conf.csdn.auto_read_full === true) {
  105. if (api.isContains(api.getDomain(), "blog.csdn.net")) {
  106. var btnReadmore = $("#btn-readmore");
  107. var articleBox = $("div.article_content");
  108. //先去除阅读更多部分的style(隐藏)
  109. articleBox.removeAttr("style");
  110. //再删除越多更多按钮
  111. btnReadmore.parent().remove();
  112. }
  113. }
  114. //CSDN文章详情页关闭底部登录注册框
  115. if (conf.csdn.auto_close_loginbox === true) {
  116. if (api.isContains(api.getDomain(), "blog.csdn.net")) {
  117. var pb = $('.pulllog-box');
  118. //隐藏显示
  119. pb[0].style.display = 'none';
  120. }
  121. }
  122. //CSDN删除asideFooter-侧栏底部,如联系我们
  123. if (conf.csdn.auto_remove_asidefooter === true) {
  124. if (api.isContains(api.getDomain(), "blog.csdn.net")) {
  125. //删除左侧栏底部
  126. $('#asideFooter').remove();
  127. }
  128. }
  129. //console.log("ST-Script is over");
  130. })();