Skip to content

Instantly share code, notes, and snippets.

@mxamber
Created August 31, 2019 02:37
Show Gist options
  • Save mxamber/f35f68940de8908fe17f5f60d00fefe7 to your computer and use it in GitHub Desktop.
Save mxamber/f35f68940de8908fe17f5f60d00fefe7 to your computer and use it in GitHub Desktop.
A Tampermonkey userscript to display some stats on AO3: the percentage of all visitors (hits) that left a kudo, comment, or bookmarked the story.
// ==UserScript==
// @name AO3 Stats
// @namespace http://tampermonkey.net/
// @version 1.0
// @description display ao3 stats
// @author mxamber
// @match https://archiveofourown.org/works/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var kudos_elem = document.querySelector("dl.stats dd.kudos");
var kudos;
if(typeof(kudos_elem) != 'undefined' && kudos_elem != null) {
kudos = kudos_elem.innerHTML;
} else {
kudos = 0;
}
var comments_elem = document.querySelector("dl.stats dd.comments");
var comments;
if(typeof(comments_elem) != 'undefined' && comments_elem != null) {
comments = comments_elem.innerHTML;
} else {
comments = 0;
}
var bookmarks_elem = document.querySelector("dl.stats dd.bookmarks > a");
var bookmarks;
if(typeof(bookmarks_elem) != 'undefined' && bookmarks_elem != null) {
bookmarks = bookmarks_elem.innerHTML;
} else {
bookmarks = 0;
}
var hits_elem = document.querySelector("dl.stats dd.hits");
var hits;
if(typeof(hits_elem) != 'undefined' && hits_elem != null) {
hits = hits_elem.innerHTML;
} else {
hits = 0;
}
console.log("hits: " + hits + ", comments: " + comments + ", kudos: " + kudos);
var box = document.createElement("div");
box.setAttribute("style", "font-size: 14px; z-index: 50; padding: 1em; border-radius: 0 0.5em 0.5em 0; border: 1px solid black; border-left: none; box-shadow: 0.5em 0.5em 1em rgba(0,0,0,0.5); color: black; background: rgba(255,255,255,0.7); position: absolute; top: 50vh; left: 0px;");
box.innerHTML = "<p>Kudos: " + Math.floor(kudos/hits * 10000)/100 + "%</p>";
box.innerHTML += "<p>Comments: " + Math.floor(comments/hits * 10000)/100 + "%</p>";
box.innerHTML += "<p>Bookmarks: " + Math.floor(bookmarks/hits * 10000)/100 + "%</p>";
document.body.appendChild(box);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment