stackoverflowToCN

将英文版的stackoverflow跳转到中文版stackoom!

As of 2020-06-27. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name stackoverflowToCN
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 将英文版的stackoverflow跳转到中文版stackoom!
  6. // @author 岳华
  7. // @match https://stackoverflow.com/questions/*
  8. // @namespace https://greatest.deepsurf.us/zh-CN/users/660626-lagrange-doggy
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Your code here...
  16. function addLink(fragment, text, href){
  17. //let a = imdblink.cloneNode(true);//let作用:a只在所在的代码块内有效!
  18.  
  19. fragment.textContent = text;//克隆写结点后做文本的替换
  20. fragment.href = href;
  21. }
  22.  
  23. function insertAfter(newNode, referenceNode) {
  24. referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
  25. return newNode;
  26. }
  27.  
  28.  
  29. let title = document.title;//python - How to using @roles required in flask? - Stack Overflow
  30. let start = title.indexOf("-");
  31. let end = title.lastIndexOf("-");
  32. title=title.substring(start+2, end-1);
  33. var links = document.querySelectorAll (
  34. ".grid.fw-wrap.pb8.mb16.bb.bc-black-2 > div"//#info标签下的a标签
  35. );//结点的集合
  36. let scanf = document.createElement("scanf");
  37. scanf.textContent=" 🚩";
  38. insertAfter(scanf, links[2]);
  39.  
  40. links = document.querySelectorAll (
  41. ".grid.fw-wrap.pb8.mb16.bb.bc-black-2 > div"
  42. )
  43.  
  44. let dev = links[0].cloneNode(false);
  45.  
  46.  
  47. let a = document.createElement("a");
  48. a.setAttribute("target", "blank");
  49.  
  50. dev.appendChild(a);
  51.  
  52. addLink(a, " 中文stackoverflow ", 'https://stackoom.com/search?q=' + title);
  53.  
  54. insertAfter(dev, scanf);
  55. })();