Google服务替换助手

这是一个脚本替换工具,将GoogleAPI替换成国内的镜像

  1. // ==UserScript==
  2. // @name Gapi-Replacer
  3. // @name:zh-CN Google服务替换助手
  4. // @namespace http://github.com/gavinin
  5. // @version 1.0
  6. // @description The script is using in some location which can't connect to google service
  7. // @description:zh-cn 这是一个脚本替换工具,将GoogleAPI替换成国内的镜像
  8. // @author Gavinin
  9. // @grant none
  10. // @match http://*/*
  11. // @match https://*/*
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15.  
  16. (function () {
  17. /*务必填写API地址
  18. 可以替换成bootcdn等,loli是我自己在用,因为比较全*/
  19. var replaceArrays = {
  20. script: {
  21. "googleusercontent.com": "loli.net",
  22. "googleapis.com": "loli.net",
  23. "www.recaptcha.net/recaptcha/": "www.google.com/recaptcha/"
  24. },
  25. link: {
  26. "googleapis.com": "loli.net",
  27. }
  28.  
  29. }
  30.  
  31. var type2Node={
  32. script:"src",
  33. link:"href"
  34. }
  35.  
  36. "use strict";
  37. for (var type in replaceArrays) {
  38. if (Object.prototype.hasOwnProperty.call(replaceArrays, type)) {
  39. for (var key in replaceArrays[type]) {
  40. if (Object.prototype.hasOwnProperty.call(replaceArrays[type], key)) {
  41. console.log(key, replaceArrays[type][key])
  42. querySelector({type:type,nodeName:type2Node[type]}, key, replaceArrays[type][key])
  43. }
  44. }
  45. }
  46. }
  47. })();
  48. function querySelector(config, originUrl, replacedUrl) {
  49. document.querySelectorAll(config.type).forEach((function (e) {
  50. if (e[config.nodeName].indexOf(originUrl) >= 0) {
  51. var newObj = e[config.nodeName].replace("http://", "https://")
  52. .replace(originUrl, replacedUrl);
  53. e.parentNode.replaceChild(function (e) {
  54. var newObj = document.createElement(config.type);
  55. return newObj.src = e, newObj;
  56. }(newObj), e);
  57. }
  58. }));
  59. }
  60.  
  61.  
  62.  

QingJ © 2025

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