User Tools

Site Tools


greasemonkey:ii-wikilink

ii-wikilink

ii-wikilink.user.js
// ==UserScript==
// @name        ii-wikilink
// @description expands dokuwiki-style links typed into text fields into urls that point to the Wiki of Lies
// @author      Full Metal Lion
// @namespace   http://enquirer.improbableisland.com/dokuwiki/doku.php?id=greasemonkey
// @match       *://*.improbableisland.com/*
// @exclude     *://enquirer.improbableisland.com/dokuwiki/*
// @icon        http://improbableisland.com/favicon.ico
// @version     1.2
// @grant       none
// ==/UserScript==
 
//This script does not support interwiki links, but I guess a future version could.
 
var bracketsr = /\[\[(.*?)\]\]/;
//matches brackets and captures what's between them,
 
var underscoresr = /[^a-zA-Z0-9-.:#?;\/@&=+$,]+/g;
//matches characters to replace them with underscores.
//this regex matches all but the characters that might mean something to dokuwiki
//the purpose of this process is to avoid breaking II's url detection
 
var url = "enquirer.improbableisland.com/dokuwiki/doku.php?id=";
var boxes = document.querySelectorAll('input, textarea');
for(var i=0; i<boxes.length; i++){
  boxes[i].addEventListener("input", function(event){
    target = this.value;
    target = bracketsr.exec(target)[1]; //get the capture group
    target = target.replace(/\?/,"&"); //support url parameters
    target = target.replace(underscoresr, "_");
    this.value =(this.value.replace(bracketsr, url+target));
  });
};
greasemonkey/ii-wikilink.txt · Last modified: 2023/11/21 18:04 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki