From: Dariusz Murakowski Date: Thu, 13 Jul 2017 20:14:54 +0000 (-0400) Subject: MIT's new The Tech: put article headline in X-Git-Url: http://src.murakowski.org/?a=commitdiff_plain;h=8d8d11af5be26f6cd13d1a62b806a8ada3c2ead3;p=userscripts.git MIT's new The Tech: put article headline in <title> --- 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