您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Trimmer for Reddit
当前为
// ==UserScript== // @name Trim Reddit // @namespace stgeorge // @description Trimmer for Reddit // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @match *://old.reddit.com/* // @match *://www.reddit.com/* // @grant GM.xmlHttpRequest // @grant GM.getValue // @grant GM.setValue // @grant GM.deleteValue // @version 2.0 // @run-at document-start // ==/UserScript== (() => { let side = null; const OPT_SIMPLIFY_HEADER = false; const OPT_NEW_LINK = true; const HEADER_KEEP = [ 'news','worldnews','Jokes','books' ]; const HEADER_ADD = { ysk:'youshouldknow', cool:'coolguides', next:'nextfuckinglevel', hbros:'humansbeingbros', abros:'animalsbeingbros', }; const HEADER_REPLACE = { explainlikeimfive:'eli5', todayilearned:'til', LifeProTips:'lpt', AskReddit:'ask', }; function trim() { $(`<style> .selected { color: blue !important; } #search { text-align: center; padding: 5px; position: revert !important; margin-top: 0 !important; } #search input { background: white !important; color: black; } #new { color: orangered !important; } #body-wrapper { display: flex; background: white; } #header { height: revert !important; position: sticky !important; } .thing { background-color:white; } .link { margin-right: revert !important; } body div.content { margin: 5px !important; } .sitetable { border-bottom: 0 !important; border-left: 0 !important; border-right:solid 1px #eeeeff !important; margin-right: revert !important; } .linklisting.sitetable { margin-right: 0 !important; } .listing-page #siteTable { margin-right: 0; } .side * { font-size: 16px !important; } .side { background: url('') !important; background-color: transparent; box-shadow: revert; width:66%; margin:5px; height:1000px; overflow-y:auto; padding-top: 0; } .side:before { content: revert !important; background: revert !important; } .side:after { content: ''; } .side .commentarea { margin-right: revert !important; } .expando-button { position: relative !important; } /* .usertext-body p { color: black !important; background: white !important; } */ .md { background: white !important; } div.md>blockquote>p { position: inherit !important; } .content:before { background-color: revert !important; background-image: revert !important; } .clicked { background-color: #eeeeff; border: solid 1px black; border-radius: 10px; } .ui-resizable-e { cursor: e-resize; width: 2px; right: -1px; top: 0; bottom: 0; background-color: blue; } #popup { position: fixed; top: 0; left:0; background:rgba(0,0,0,0.75); width:100%; height:100%; display:none; } </style>`).appendTo('head'); $('.infobar').remove(); $('.footer-parent').remove(); $('#sr-header-area').siblings().remove(); let content = $('.content[role="main"]'); content.css({ width:'33%', height: '1000px', 'overflow-y': 'auto', resize:'horizontal', margin: '0', }); // // We make the right-hand side sidebar (.side) bigger and empty its // contents. Then, we make the main pane (.content) thinner and // use it show the list of articles. (We mark it as resizable horizontally // so that it can be widened.) When an article is clicked on in // the .content pane, we show its threaded comments in the .side pane. // // +----------------------------------------------------+ // | #header | // +----------------------------------------------------+ // | #body-wrapper (new) | // | +-------------+----------------------------------+ | // | | .content | .side | | // | |+-----------+| | | // | || #search || Posting and comments | | // | |+-----------+| | | // | || Post list || | | // | || ... || | | // | |+-----------+| | | // | +-------------+----------------------------------+ | // +----------------------------------------------------+ // let wrapper = $('<div id="body-wrapper"></div>'); $('#header').after(wrapper); wrapper.append(content); content.prepend($('#search').detach()); side = $('.side'); side.empty(); wrapper.append(side); let curbg = 'white'; let first = null; $('.entry a').add('.search-result a').add('a.title') .each(function(k,v) { let t = $(this).closest('.thing'); if (t.length == 0) t = $(this).closest('.search-result'); let a = $(this); let href = a.attr('href'); if (href.indexOf('/comments/') != -1) { a.on('click', function(e) { e.preventDefault(); e.stopPropagation(); t.css({'background-color':'#eeeeff'}); t.addClass('clicked'); t.siblings().css({'background-color':curbg}); t.siblings().removeClass('clicked'); href = href.replace('www.reddit.com', 'old.reddit.com'). replace('//reddit.com', '//www.reddit.com'); (async () => {await GM.setValue('lastseen', href)})(); loadComment(href); }); if (first === null && !t.hasClass('stickied')) { first = a; } } }); (async() => { let last_seen = await GM.getValue('lastseen', null); GM.deleteValue('lastseen'); let l = null; if (last_seen) { l = $('a[href="'+last_seen+'"]'); } let to_show = (l && l.length > 0) ? l : first; if (to_show) { to_show.click(); } })(); } function loadComment(u) { GM.xmlHttpRequest({ method: "GET", url: u+'?sort=new', onload: function(response) { side.html($.parseHTML(response.responseText)); let c = side.find('.content[role="main"]').detach(); side.empty(); side.append(c); c.css({margin:'10px'}); side.find('.infobar').detach(); side.find('.thing .child .expand').click(); // Collapse sub-comments. side.find('a').each(function(k,v) { let anchor = $(this); let href = anchor.attr('href'); if (!href) return true; $(['imgur.com','i.imgur.com','preview.redd.it','youtube.com']).each(function(x,y) { if (href.indexOf('/'+y+'/') != -1) { anchor.attr('target','_new'); return false; } }); }); setTimeout(function() { $(document).scrollTop(0); side.scrollTop(0); }, 500); } }); } function fixHeader() { // // If OPT_SIMPLIFY_HEADER is set, we trim the links // in the header to a chosen few :-). // If OPT_NEW_LINK is set, we add a 'new' link to to the header // to toggle between classic and new reddits. // let template = null; let i = 0; let bars = $('ul.sr-bar'); bars.find('li').each(function(k,v) { let li = $(this); if (template == null && i > 0) { template = li.clone(true); template.removeClass('selected'); if (!OPT_SIMPLIFY_HEADER) return false; } ++i; let a = li.find('a:first'); let t = a.text(); if (HEADER_KEEP.indexOf(t) == -1 && !HEADER_REPLACE[t]) { li.remove(); } else { a.attr('title', t); if (HEADER_REPLACE[t]) { a.text(HEADER_REPLACE[t]); a.attr('title',t); } } }); let bar = bars.last(); add_headers = OPT_SIMPLIFY_HEADER ? HEADER_ADD : {}; if (OPT_NEW_LINK) add_headers['new'] = top.location.href.replace('old','www'); $.each(add_headers, function(k,v) { let x = template.clone(true); let a = x.find('a'); x.prepend(a); a.attr('id', k); a.text(k+' '); a.attr('href',v.indexOf('/') != -1 ? v : '/r/'+v); a.attr('title',v); x.prependTo(bar); }); if (OPT_SIMPLIFY_HEADER) $('#header *').css({'background-color':'white','color':'black'}); } function addClassicButton() { // // If we're in the 'new' reddit, add an 'Classic' button to help // us switch to classic reddit. // if (document.URL.indexOf('www.reddit.com') != -1) { $('#email-verification-tooltip-id'). before($('<button title="Classic Reddit" id="classic-button" type="button">Classic</button>')); let classic = $('#classic-button'); classic.css({ margin: '10px', border: 'solid 1px #0079d3', padding: '8px', width: '120px', 'border-radius': '9999px', color: '#0079d3', 'font-weight': 'bold', }); classic.on('click', function() { top.location.hostname = 'old.reddit.com'; }); return; } } // Main. // The setTimeout is there to handle race conditions to run our // script after reddit loads all its scripts. Doesn't seem to work // always :-( // setTimeout(function() { addClassicButton(); // If we're already in the comments page, nothing more to do. if (document.URL.indexOf('/comments/') == -1) { trim(); fixHeader(); } }, 1000); })();