Skip to content

Instantly share code, notes, and snippets.

@maxerickson
Last active November 1, 2018 12:40
Show Gist options
  • Save maxerickson/f729e5ded1f0aff1dbe983129b26471c to your computer and use it in GitHub Desktop.
Save maxerickson/f729e5ded1f0aff1dbe983129b26471c to your computer and use it in GitHub Desktop.
Ease copying OSM tags for Wikipedia entry.
// ==UserScript==
// @name Wiki tags
// @namespace maxerickson
// @version 0.1
// @description Add osm style key=value tags to wikipedia pages.
// @author Max Erickson
// @match *://*.wikipedia.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var wikipedia=document.getElementById("firstHeading").textContent;
var wikidata=document.getElementById("t-wikibase").firstChild.href;
var re = /https?:\/\/www.wikidata.org\/wiki\/Special:EntityPage\/(.*)|/;
var wd2=re.exec(wikidata)[1];
var tags=document.createElement("span");
var prefix=document.location.hostname.slice(0,2);
var fill="";
tags.style.position="absolute";
tags.style.top="10px";
tags.style.left="30%";
tags.style.padding="10px";
tags.style.backgroundColor="white";
tags.style.outline="black solid";
fill="wikipedia="+prefix+":"+wikipedia+"<br/>wikidata="+wd2;
fill=fill+'<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"brand:wikidata": "'+wd2;
fill=fill+'",<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"brand:wikipedia": "'+prefix+':'+wikipedia+'",';
tags.innerHTML=fill;
document.body.append(tags);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment