User:CarrONoir/common.js: Difference between revisions

From The Fifth City Wiki
Cite gen
 
Blank, now part of common
Tags: Blanking Manual revert
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
$(function () {
const citebox = document.getElementById('citegen');
if (citebox === null) {return;}
const output = document.createElement('p');
const input = document.createElement('input');
const auto_check = document.createElement('input');
const check_label = document.createElement('label');
output.id = 'citegen_output';
output.innerHTML = '&ltref>{{Citation|||Fallen London|}}&lt/ref&gt';
auto_check.type = 'checkbox';
auto_check.id = 'citegen_auto';
auto_check.name = 'citegen_auto';
check_label.for = 'citegen_auto';
check_label.innerHTML = 'Auto copy to clipboard?';
input.type = 'text';
input.placeholder = "FL wiki URL";
input.id = 'citegen_input';
input.name = 'citegen_input';
input.style.width = '50%';
citebox.append(input);
citebox.append(auto_check);
citebox.append(check_label);
citebox.append(output);
input.addEventListener('keyup', function(){convert(input, output, auto_check);});
input.focus();
}());


function convert(input, output, autocopy) {
var newlink = input.value;
var url = newlink;
var name = newlink.substring(31);
name = name.replace(/_/g, ' ');
name = name.replace(/%21/g, '!');
name = name.replace(/%22/g, '\'');
name = name.replace(/%27/g, '\'');
name = name.replace(/%28/g, '(');
name = name.replace(/%29/g, ')');
name = name.replace(/%2C/g, ',');
name = name.replace(/%3F/g, '?');
newlink = '&ltref>{{Citation|' + url + '|' + name + '|Fallen London|}}&lt/ref&gt';
output.innerHTML = newlink;
if (autocopy.checked === true) {
navigator.clipboard.writeText('<ref>{{Citation|' + url + '|' + name + '|Fallen London|}}</ref>');
}
}

Latest revision as of 21:28, 21 November 2023