ArkhamDB: put deck name in <title>
authorDariusz Murakowski <murakdar@gmail.com>
Thu, 19 Oct 2017 20:15:42 +0000 (16:15 -0400)
committerDariusz Murakowski <murakdar@gmail.com>
Thu, 19 Oct 2017 20:15:42 +0000 (16:15 -0400)
(ArkhamDB) Arkham Horror LCG Card Game deck title.user.js [new file with mode: 0644]

diff --git a/(ArkhamDB) Arkham Horror LCG Card Game deck title.user.js b/(ArkhamDB) Arkham Horror LCG Card Game deck title.user.js
new file mode 100644 (file)
index 0000000..f01966f
--- /dev/null
@@ -0,0 +1,27 @@
+// ==UserScript==
+// @name         (ArkhamDB) Arkham Horror LCG Card Game deck title
+// @namespace    http://tampermonkey.net/
+// @version      0.1
+// @description  append deck name to page title
+// @author       Dariusz Murakowski
+// @match        https://arkhamdb.com/deck/view/*
+// @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');
+    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').text();
+})();
\ No newline at end of file