MIT's new The Tech: put article headline in <title>
authorDariusz Murakowski <murakdar@gmail.com>
Thu, 13 Jul 2017 20:14:54 +0000 (16:14 -0400)
committerDariusz Murakowski <murakdar@gmail.com>
Thu, 13 Jul 2017 20:14:54 +0000 (16:14 -0400)
(MIT's The Tech) useful title; TODO- check for -article- tag.user.js [new file with mode: 0644]

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 (file)
index 0000000..2f36eb4
--- /dev/null
@@ -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