Skip to content

Instantly share code, notes, and snippets.

@ethe
Created June 18, 2018 11:48
Show Gist options
  • Select an option

  • Save ethe/c7bae987457bc77eee128bd9a6c1dd94 to your computer and use it in GitHub Desktop.

Select an option

Save ethe/c7bae987457bc77eee128bd9a6c1dd94 to your computer and use it in GitHub Desktop.
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