Skip to content

Instantly share code, notes, and snippets.

@JustusW
Created October 13, 2018 10:47
Show Gist options
  • Save JustusW/f5c4f4872f23be413ddc84e2abb0adae to your computer and use it in GitHub Desktop.
Save JustusW/f5c4f4872f23be413ddc84e2abb0adae to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Quotationmarker
// @description Marks the quotations asterisks on warhammer-community and regimental-standard and adds hyperlinks as well as a hover.
// @version 0.1
// @grant none
// @include https://www.warhammer-community.com/*
// @include https://regimental-standard.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript==
$(function() {
var targets = {};
var bases = [];
$("span:contains(*)").each(function (i, e) {
var txt = e.innerText.trim();
if ( txt.startsWith('*') ) {
var name = txt.split(' ', 1)[0];
targets[name] = txt.replace(name, '').trim();
e.innerHTML = '<a name="tmpanchor' + name.length + '"></a>' + e.innerHTML;
} else {
bases.push($(e));
}
});
bases.forEach(function (obj) {
var txt = obj.get(0).innerHTML;
$.each(targets, function (name, obj) {
regex = new RegExp('[^* ](' + name.split('*').join('\\*') + ')[^*]');
var match = txt.match(regex);
if (match) {
match.forEach(function (rpl) {
if (rpl.startsWith('*')) {
txt = txt.replace(rpl, '<a href="#tmpanchor' + name.length + '" title="' + obj.split('"').join('\\"') + '">' + rpl + '</a>');
}
});
}
});
obj.get(0).innerHTML = txt;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment