Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Reddit - Add context to links
- // @namespace http://userscripts.org
- // @author gavin19
- // @description Add context to links that don't have any
- // @match http://*.reddit.com/*/*/comments/*
- // @match https://*.reddit.com/*/*/comments/*
- // @include http://*.reddit.com/*/*/comments/*
- // @include https://*.reddit.com/*/*/comments/*
- // @version 1.0
- // ==/UserScript==
- (function () {
- var addContext = {
- contextLevel: 3, /** Change this value to increase/decrease the context level **/
- processLinks: function ( links ) {
- var i, len,
- a = links || document.querySelectorAll( '.comment .md a[href*="/comments/"]' ),
- cx = '?context=';
- for ( i = 0, len = a.length; i < len ; i +=1 ) {
- if ( a[i].href.indexOf( cx ) === -1 ) {
- a[i].href += cx + this.contextLevel;
- }
- }
- },
- init: function () {
- var t;
- document.body.addEventListener( 'DOMNodeInserted', function ( e ) {
- t = e.target;
- if ( t.localName === 'div' && t.id && t.id.indexOf( 'siteTable' ) !== -1 ) {
- addContext.processLinks( t.querySelectorAll( '.comment .md a[href*="/comments/"]' ) );
- }
- }, true );
- addContext.processLinks( document.querySelectorAll( '.comment .md a[href*="/comments/"]' ) );
- }
- };
- if ( document.body && document.querySelector( '.comments-page' ) ) {
- setTimeout(function () {
- addContext.init();
- }, 300);
- }
- }());
Add Comment
Please, Sign In to add comment