Created
June 18, 2018 11:48
-
-
Save ethe/c7bae987457bc77eee128bd9a6c1dd94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function replaceAllLink() { | |
| var ruleMap = new Map( | |
| [ | |
| ["link.zhihu.com/?target=", [ | |
| "http://link.zhihu.com/?target=", | |
| "https://link.zhihu.com/?target=" | |
| ]] | |
| ] | |
| ) | |
| var as = document.getElementsByTagName("a"); | |
| for (var i = 0; i < as.length; i++) { | |
| for (var rule of ruleMap) { | |
| if (as[i].href.indexOf(rule[0]) !== -1) { | |
| var h = as[i].href | |
| for (var replaceString of rule[1]) { | |
| h = h.replace(replaceString) | |
| } | |
| as[i].href = decodeURIComponent(h) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment