forked from arthurlacoste/mastodon-lang-remover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmastodonLangRemover.user.js
80 lines (66 loc) · 3.36 KB
/
mastodonLangRemover.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ==UserScript==
// @name mastodonLangRemoverJS
// @namespace https://arthurlacoste.com
// @version 0.0.1
// @description Remove a lang from web interface
// @author Arthur Lacoste <[email protected]>, Bernard McKeever <[email protected]>
// @match *://*/web/*
// @match *://*/settings/preferences
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://raw.githubusercontent.com/pietrasiak/jquery.initialize/master/jquery.initialize.min.js
// @connect obscure-fjord-89228.herokuapp.com
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
$(".status").initialize(function () {
getTranslation($(this));
});
function getTranslation(toot) {
var langText = {};
var text = toot.children('.status__content').text().replace(/(?:https?|ftp):\/\/[\n\S]+/g, '');
var regex = /[\u3000-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\uFF00-\uFFEF]|[\u4E00-\u9FAF]|[\u2605-\u2606]|[\u2190-\u2195]|\u203B|[àâäèèéêëîïííñôóœùûüÿçÀÂÄÈÉÊËÎÏÍÔŒÙÚÛÜŸÇ]/g;
if(regex.test(text)) {
toot.hide();
}
return String(GM_getValue('lang', 'ja'));
}
function saveSettings(event) {
if (event.target.tagName.toLowerCase() === 'button' && event.target.textContent === 'Save changes') {
event.preventDefault();
var input = document.getElementById('translation_locale');
var selectedLanguage = input.options[input.selectedIndex].value;
GM_setValue('lang', selectedLanguage);
setTimeout(function() {
document.querySelector('body').removeEventListener('click', saveSettings, false);
actions.children[0].click();
}, 500);
}
}
if (window.location.pathname === '/settings/preferences') {
// We're on the settings page
var form = document.querySelector('form.simple_form');
var actions = document.querySelector('div.actions');
var settingsGroup = form.querySelector('div.fields-group').cloneNode(true);
settingsGroup.children[1].remove(); // Remove the privacy element from the clone
var notice = document.createElement('div');
var noticeMsg = 'Select here the langage you want to remove.';
notice.setAttribute('id', 'translation_notice');
notice.innerHTML = '<h3 style="color: #d9e1e8; font-size: 20px; line-height: 24px; font-weight: 400; margin-bottom: 20px;">Lang Remover</h3><p style="margin-bottom: 20px;">'+noticeMsg+'</p>';
var languageDiv = settingsGroup.children[0];
languageDiv.classList.remove('user_locale');
languageDiv.classList.add('translation_locale');
var label = languageDiv.children[0].children[0];
label.setAttribute('for', 'translation_locale');
label.textContent = 'Language to remove';
var input = languageDiv.children[0].children[1];
input.setAttribute('name', 'user[translation]');
input.setAttribute('id', 'translation_locale');
input.value = GM_getValue('lang', 'ja');
settingsGroup.insertBefore(notice, languageDiv);
form.insertBefore(settingsGroup, actions);
document.querySelector('body').addEventListener('click', saveSettings, false);
}
})();