From 8d8d11af5be26f6cd13d1a62b806a8ada3c2ead3 Mon Sep 17 00:00:00 2001 From: Dariusz Murakowski Date: Thu, 13 Jul 2017 16:14:54 -0400 Subject: [PATCH] MIT's new The Tech: put article headline in --- ...ul title; TODO- check for -article- tag.user.js | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 (MIT's The Tech) useful title; TODO- check for -article- tag.user.js diff --git a/(MIT's The Tech) useful title; TODO- check for -article- tag.user.js b/(MIT's The Tech) useful title; TODO- check for -article- tag.user.js new file mode 100644 index 0000000..2f36eb4 --- /dev/null +++ b/(MIT's The Tech) useful title; TODO- check for -article- tag.user.js @@ -0,0 +1,27 @@ +// ==UserScript== +// @name (MIT's The Tech) useful title; TODO: check for <article> tag +// @namespace http://tampermonkey.net/ +// @version 0.1 +// @description append article headline to page title +// @author Dariusz Murakowski +// @match https://thetech.com/* +// @grant none +// @run-at document-end +// ==/UserScript== + +// this works for news articles. For static pages, +// look for a.active inside div.static-pages-nav? TODO. + +(function() { + 'use strict'; + + // from https://stackoverflow.com/questions/12685963/get-element-by-tag-and-class + // and https://stackoverflow.com/questions/18242171/get-element-by-tag-name-and-class-name + var hl_nodes = document.querySelectorAll('h1.headline'); + if (hl_nodes.length == 1) { + var headline = hl_nodes[0].innerHTML; + console.log(headline); + document.title = document.title + " - " + headline; + } + // alternatively, using jQuery: var headline = $('h1.headline').text(); +})(); \ No newline at end of file -- 2.7.4