User:CarrONoir/common.js
From The Fifth City Wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
$(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 = '<ref>{{Citation|||Fallen London|}}</ref>'; 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 = '<ref>{{Citation|' + url + '|' + name + '|Fallen London|}}</ref>'; output.innerHTML = newlink; if (autocopy.checked === true) { navigator.clipboard.writeText('<ref>{{Citation|' + url + '|' + name + '|Fallen London|}}</ref>'); } }