ST-Script

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

当前为 2018-06-15 提交的版本,查看 最新版本

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