change url links on document load
i have this js bookmarklet that makes all the current page's font colors black. what i wanted is to maintein the effect of the bookmarklet even clicking on the page's links
javascript:(
function(){
var newSS, styles='* { color: black !important }';
if(document.createStyleSh开发者_StackOverfloweet) {
document.createStyleSheet("javascript:'"+styles+"'");
} else {
newSS=document.createElement('link');
newSS.rel='stylesheet';
newSS.href='data:text/css,'+escape(styles);
document.getElementsByTagName("head")[0].appendChild(newSS);
}
}
)();
so i though if there is a way we can change the current page's links into something like
<a href="javascript:'load link location' then 'apply color effect'">Link</a>
*cant actually think of the right codes lol i don't want to use stylish addons or something like that xD
So there are a couple of parts to this:
- Write some javascript to intercept all link clicks and redirect to your function. See Use Javascript to Intercept All Document Link Clicks.
- Write the function that gets called on link intercept. This function would do the following:
- Pull the href of the link and place it in
document.location
. - Call your black highlight function
- Pull the href of the link and place it in
So roughly the code would look something like this:
functionToHighlightTextBlack(); // Apply to current page
// Apply to future page
for (var ls = document.links, numLinks = ls.length, i=0; i < numLinks; i++){
ls[i].onClick = function() {
document.location = ls[i].href;
functionToHighlightTextBlack();
}
}
精彩评论