|
|
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 = '<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>');
| |
| }
| |
| }
| |