Greasy Fork

The Verge Parental Control

Removes stories from The Verge's based on keywords, modify it to suit your needs. Defaults to removing "monkey business" stories.

当前为 2018-01-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         The Verge Parental Control
// @namespace    https://theverge.com
// @version      0.3.0
// @description  Removes stories from The Verge's based on keywords, modify it to suit your needs. Defaults to removing "monkey business" stories. 
// @author       GingersAreAwesome
// @license      MIT
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js
// @match        https://www.theverge.com/*
// @run-at document-start
// ==/UserScript==

/* jshint ignore:start */
var inline_src = (<><![CDATA[
  /* jshint ignore:end */
  /* jshint esnext: false */
  /* jshint esversion: 6 */

  // Blacklist
  let ban = [ // Must be lower case
    /rape/,
    /sex/,
    /harass/,
    /allegation/,
    /believed/,
    /#metoo/
  ]

  // DO NOT TOUCH
  // TODO: bubble up to element with entry in class, remove it.
  let removeArticle = (no) => {
    no.style.opacity = 0.0
    let article = no
    do {
      article = article.parentNode
      if (article === document.documentElement) { return }
      if (! article) { return }
    } while (article && ! article.className.match(/c-entry-box--compact /))
    
    if (
        article
        && article.parentNode
        && article.parentNode.className.match(/c-compact-river__entry /) 
    ) {
      article.parentNode.remove()
    } else if ( article ){
      article.remove()
    }
  }

  window.addEventListener('DOMContentLoaded', function() {

    console.log('TVBK TamperMonkey script deployed.')

    _.set(document.querySelector('.c-masthead__dateline'), 'style.display', 'none')
    _.set(document.querySelector('.c-rock-list'), 'style.display', 'none')

    let links = document.querySelectorAll('a')
    console.log('TVBK: Found ' + links.length + ' links.')
    ban.forEach(word => {
      links.forEach(link => {
        if(link.text.toLowerCase().match(word)){
          console.log(`badword discovered in link: ${link.text}`)
          removeArticle(link)
        }
      })
    })
    window.document.documentElement.style.visibility = 'visible'
  }, true)
/* jshint ignore:start */
]]></>).toString();
// dom is not completely populated yet, but body element should be
window.document.documentElement.style.visibility = 'hidden'

var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] });
eval(c.code);
/* jshint ignore:end */