Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name 4chan - Translate to and from Ente Islean
- // @version 1.1
- // @author Hanzou URUSHIHARA
- // @include http://boards.4chan.org/a/res/*
- // @include https://boards.4chan.org/a/res/*
- // @run-at document-end
- // ==/UserScript==
- (function(){
- var d = document;
- var alpha_eng = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- var alpha_ente = 'AZYXEWVTISRQPNOMLKJHUGFDCBazyxewvtisrqpnomlkjhugfdcb';
- var tranChar = function(c_eng) {
- var x = alpha_eng.indexOf(c_eng);
- return x === -1 ? c_eng : alpha_ente[x];
- };
- var translate = function() {
- var nodes = d.evaluate('.//text()', post.nodes.comment, null, 7, null);
- for (var i = 0; i < nodes.snapshotLength; i++) {
- var node = nodes.snapshotItem(i);
- var eng = node.data;
- var ente = '';
- for (var j = 0; j < eng.length; j++) {
- ente += tranChar(eng[j]);
- }
- node.data = ente;
- }
- };
- var post;
- var a = d.createElement('a');
- a.textContent = 'Translate';
- a.addEventListener('click', translate, false);
- d.dispatchEvent(new CustomEvent('AddMenuEntry', {
- detail: {
- el: a,
- open: function(p) {
- post = p;
- return true;
- },
- type: 'post'
- }
- }));
- // QR stuff
- var keyEvtListMaou = function(e) {
- if (!(e.altKey && e.keyCode === 88)) {
- return;
- }
- // Alt + X is pressed
- var eng = this.value;
- var ente = '';
- for (var i = 0; i < eng.length; i++) {
- ente += tranChar(eng[i]);
- }
- this.value = ente;
- };
- var setupQRListener = function() {
- d.getElementById('qr').querySelector('textarea').addEventListener('keyup', keyEvtListMaou, false);
- };
- if (d.getElementById('qr')) {
- setupQRListener();
- } else {
- d.addEventListener('QRDialogCreation', setupQRListener, false);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement