r/ScriptSwap • • Jul 18 '16

Javascript Script for RES. The "expando" button sets more links as visited

When navigating Reddit with RES I like to see links turn purple when using the expand button to see an image, twitter link or a text-post.

This script adds the link to your history thus making it purple.

Not working with some external links like youtube or i.reddituploads.com

I hope you find it useful and any advice is appreciated.

The script: https://github.com/esantini/Reddit_Set_Visited_Links/blob/master/script.js

Put it on the console or in your scripts in Tampermonkey or other extensions like that

// Reddit: on expando-button click: set visited link by modifying the history
document.getElementById('siteTable').addEventListener('click', function(ev){
	try {
		if(ev.target.classList.contains('expando-button')) {
			var url = ev.target.parentElement.querySelector('.title a').href;
			var currUrl = window.location.href;

			// set clicked URL in the browser URL bar.
			history.replaceState({}, '', url);

			// reSet current URL
			history.replaceState({}, '', currUrl);
		}
	}
	catch (e) {
		// fails with some external links like youtube
	}
});    
3 Upvotes

0 comments sorted by