Edenya-Script

Addon Edenya

目前為 2018-07-21 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Edenya-Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.100019
  5. // @description Addon Edenya
  6. // @author Valkazaar
  7. // @match http://www.edenya.net/_vahal/*
  8. // @grant none
  9. // @include http://www.edenya.net/_vahal/*
  10. // @include https://www.edenya.net/_vahal/*
  11. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
  12. // ==/UserScript==
  13.  
  14. function checkMessages(){
  15. $.ajax({
  16. type: 'GET',
  17. url: 'https://www.edenya.net/index2.php?loca=communiquer/forum/messages',
  18. //data: datas,
  19. success: function(data) {
  20. var i = (data.split("#AA2020")).length - 1;
  21. if(i>0){
  22. $('#ValkHidden').html('<a href="https://www.edenya.net/index2.php?loca=communiquer/forum/messages">'+i + (i > 1 ? ' messages non lus':' message non lu')+'</a>');
  23. }
  24. }});
  25. }
  26. function Valk_Del(item){
  27. var z = localStorage.getItem('EdenyaShortcut');
  28. z = JSON.parse(z);
  29. delete z[item];
  30. localStorage.setItem('EdenyaShortcut',JSON.stringify(z));
  31. Valk_Refresh();
  32. }
  33. function Valk_Refresh(){
  34. var first = true;
  35. var z = localStorage.getItem('EdenyaShortcut');
  36. z = JSON.parse(z);
  37. var menuToAdd = document.getElementById('menuValk');
  38. menuToAdd.innerText='';
  39. for (var item in z) {
  40. var linkToUp = document.createElement('img');
  41. linkToUp.setAttribute('src', '../images/arrow-up.gif');
  42. linkToUp.setAttribute('onclick', 'Valk_Up(\"' + item + '\");');
  43. var linkToDown = document.createElement('img');
  44. linkToDown.setAttribute('src', '../images/arrow-down.gif');
  45. linkToDown.setAttribute('onclick', 'Valk_Down(\"' + item + '\");');
  46. var linkToModify = document.createElement('img');
  47. linkToModify.setAttribute('src', '../images/edit.png');
  48. linkToModify.setAttribute('onclick', 'Valk_Rename(\"' + item + '\");');
  49. var linkToDelete = document.createElement('img');
  50. linkToDelete.setAttribute('src', '../images/bad.gif');
  51. linkToDelete.setAttribute('onclick', 'Valk_Del(\"' + item + '\");');
  52. var ligneShortcut = document.createElement('li');
  53. var linkShortcut = document.createElement('a');
  54. linkShortcut.setAttribute('href', z[item]);
  55. linkShortcut.innerText = item;
  56. first == false ? ligneShortcut.appendChild(linkToUp): first = false;
  57. ligneShortcut.appendChild(linkToDown);
  58. ligneShortcut.appendChild(linkToModify);
  59. ligneShortcut.appendChild(linkToDelete);
  60. ligneShortcut.appendChild(linkShortcut);
  61. menuToAdd.appendChild(ligneShortcut);
  62. }
  63. //test();
  64.  
  65. }
  66.  
  67. function Valk_Add(){
  68. var nom=prompt('Nom du shortcut ?');
  69. if (nom!==null){
  70. var z = localStorage.getItem('EdenyaShortcut');
  71. z = JSON.parse(z);
  72. z[nom]=document.URL;
  73. localStorage.setItem('EdenyaShortcut',JSON.stringify(z));
  74. Valk_Refresh();
  75. }
  76. }
  77.  
  78. function Valk_Up(itemIn){
  79. var previous = null;var y={};
  80. var z = localStorage.getItem('EdenyaShortcut');
  81. z = JSON.parse(z);
  82. for (let item in z) {
  83. if (previous != null){
  84. if (item == itemIn){
  85. y[item]=z[item];
  86. }
  87. for (bidule in previous){
  88. if (bidule != itemIn){
  89. y[bidule]=previous[bidule];
  90. }
  91. }
  92. };
  93. previous={};
  94. previous[item]=z[item]
  95. ;
  96. }
  97. for (var bidule in previous) {
  98. if (bidule != itemIn){
  99. y[bidule]=previous[bidule];
  100. }
  101. }
  102. localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();
  103. }
  104.  
  105. function Valk_Down(itemIn) {
  106. var next = null;
  107. var y = {};
  108. var z = localStorage.getItem('EdenyaShortcut');
  109. z = JSON.parse(z);
  110. for (var item in z) {
  111. if (item != itemIn) {
  112. y[item] = z[item];
  113. if (next != null) {
  114. for (var bidule in next) {
  115. y[bidule] = next[bidule];
  116. }
  117. next = null;
  118. }
  119. }else {
  120. next = {};
  121. next[item] = z[item];
  122. }
  123. }
  124. localStorage.setItem('EdenyaShortcut', JSON.stringify(y));
  125. Valk_Refresh();
  126. }
  127. function Valk_Rename(itemIn){
  128. var nom=prompt('A renommer en ?');
  129. if (nom!==null){
  130. var y = {};
  131. var z = localStorage.getItem('EdenyaShortcut');
  132. z = JSON.parse(z);
  133. for (var item in z) {
  134. if(item == itemIn){
  135. y[nom]=z[item];
  136. }else{
  137. y[item]=z[item];
  138. }
  139. };
  140. localStorage.setItem('EdenyaShortcut',JSON.stringify(y));
  141. Valk_Refresh();
  142. }
  143. }
  144. (function () {
  145. 'use strict';
  146. checkMessages();
  147. // Vérification de la présence de la variable localStorage EdenyaColor
  148. // et instanciation de base si nécessaire
  149. var localColor = localStorage.getItem('EdenyaColor');
  150. if (localColor === null) {
  151. localColor = {};
  152. localColor.cadre2 = '#dda0dd';
  153. localColor.ligneA = '#000000';
  154. localColor.dialogue = '#ffffff';
  155. localColor.narration = '#ffd700';
  156. localColor.cri = '#9acd32';
  157. localColor.hj = '#FFDAB9';
  158. localColor.BlackDate = '#B09070';
  159. localStorage.setItem('EdenyaColor', JSON.stringify(localColor));
  160. localColor = localStorage.getItem('EdenyaColor');
  161. }
  162.  
  163. var localColorParsed = JSON.parse(localColor);
  164. if (localColorParsed.BlackDate === undefined) {
  165. localColorParsed.BlackDate = '#B09070';
  166. localStorage.setItem('EdenyaColor', JSON.stringify(localColorParsed));
  167. }
  168.  
  169. // Remplacement des dates écrites en noir dans les forums.
  170. var x = document.getElementsByTagName("font");
  171. for (var i = 0; i < x.length; i++) {
  172. if (x[i].getAttribute('color') !== null) {
  173. x[i].setAttribute('color', (x[i].getAttribute('color')).replace('#000000', localColorParsed.BlackDate));
  174. x[i].setAttribute('color', (x[i].getAttribute('color')).replace('#990000', '#FF0000'));
  175. x[i].setAttribute('color', (x[i].getAttribute('color')).replace('\\"', ''));
  176. x[i].setAttribute('color', (x[i].getAttribute('color')).replace('\\"', ''));
  177. }
  178. }
  179.  
  180. // Colorisation des éléments
  181. var baliseHeader = document.querySelector('head');
  182. var styleToAdd = document.createElement('style');
  183. for (var item in localColorParsed) {
  184. styleToAdd.innerText += '.' +item + '{color:'+ localColorParsed[item]+'}';
  185. }
  186. styleToAdd.innerText += 'menu#menuValk {padding:0px;list-style-type: none;-webkit-padding-start: 0px;};';
  187. baliseHeader.appendChild(styleToAdd);
  188.  
  189. var scriptToAdd = document.createElement('script');
  190. scriptToAdd.setAttribute('type',"text/javascript");
  191. var t = document.createTextNode("function Valk_Del(item){var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);delete z[item];localStorage.setItem('EdenyaShortcut',JSON.stringify(z));Valk_Refresh();}\n");
  192. scriptToAdd.appendChild(t);
  193. t = document.createTextNode("function Valk_Refresh(){var first = true; var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);var menuToAdd = document.getElementById('menuValk');menuToAdd.innerText='';for (item in z) {var linkToUp = document.createElement('img');linkToUp.setAttribute('src', '../images/arrow-up.gif');linkToUp.setAttribute('onclick', 'Valk_Up(\"' + item + '\");');var linkToDown = document.createElement('img');linkToDown.setAttribute('src', '../images/arrow-down.gif');linkToDown.setAttribute('onclick', 'Valk_Down(\"' + item + '\");');var linkToModify = document.createElement('img');linkToModify.setAttribute('src', '../images/edit.png');linkToModify.setAttribute('onclick', 'Valk_Rename(\"' + item + '\");');var linkToDelete = document.createElement('img');linkToDelete.setAttribute('src', '../images/bad.gif');linkToDelete.setAttribute('onclick', 'Valk_Del(\"' + item + '\");');var ligneShortcut = document.createElement('li');var linkShortcut = document.createElement('a');linkShortcut.setAttribute('href', z[item]);linkShortcut.innerText = item;first == false ? ligneShortcut.appendChild(linkToUp): first = false;ligneShortcut.appendChild(linkToDown);ligneShortcut.appendChild(linkToModify);ligneShortcut.appendChild(linkToDelete);ligneShortcut.appendChild(linkShortcut);menuToAdd.appendChild(ligneShortcut);}}");
  194. scriptToAdd.appendChild(t);
  195. t = document.createTextNode("function Valk_Add(){var nom=prompt('Nom du shortcut ?');if (nom!==null){var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);z[nom]=document.URL;localStorage.setItem('EdenyaShortcut',JSON.stringify(z));Valk_Refresh();}}");
  196. scriptToAdd.appendChild(t);
  197. t = document.createTextNode("function Valk_Up(itemIn){var previous = null;var y={};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if (previous != null){if (item == itemIn){y[item]=z[item];}for (bidule in previous){if (bidule != itemIn){y[bidule]=previous[bidule];}}};previous={};previous[item]=z[item];}for (bidule in previous) {if (bidule != itemIn){y[bidule]=previous[bidule];}}localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();}");
  198. scriptToAdd.appendChild(t);
  199. t = document.createTextNode("function Valk_Down(itemIn) {var next = null;var y = {};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if (item != itemIn) {y[item] = z[item];if (next != null) {for (bidule in next) {y[bidule] = next[bidule];}next = null;}}else {next = {};next[item] = z[item];}}localStorage.setItem('EdenyaShortcut', JSON.stringify(y));Valk_Refresh();}");
  200. scriptToAdd.appendChild(t);
  201. t = document.createTextNode("function Valk_Rename(itemIn){var nom=prompt('A renommer en ?');if (nom!==null){var y = {};var z = localStorage.getItem('EdenyaShortcut');z = JSON.parse(z);for (item in z) {if(item == itemIn){y[nom]=z[item];}else{y[item]=z[item];}};localStorage.setItem('EdenyaShortcut',JSON.stringify(y));Valk_Refresh();}}");
  202. scriptToAdd.appendChild(t);
  203. baliseHeader.appendChild(scriptToAdd);
  204.  
  205. var locationPath = window.location.pathname.split("/");
  206. if (locationPath[locationPath.length - 2] == "_vahal" && locationPath[locationPath.length - 1] == "index.php"){
  207. // Positionnement sur la colone de gauche pour y ajouter les éléments (raccourcis et gestion des couleurs)
  208. x = document.querySelector(".menu");
  209. if (x !== null) {
  210. var imgScript = document.createElement("img");
  211. imgScript.src = "images/interface/jour/pluie/chains.gif";
  212. x.appendChild(imgScript);
  213. var divScript = document.createElement("div");
  214. var checkMsg = document.createElement("div");
  215. checkMsg.setAttribute('id','ValkHidden');
  216. divScript.appendChild(checkMsg);
  217.  
  218. var localShortcut = localStorage.getItem('EdenyaShortcut');
  219. if (localShortcut === null) {
  220. var shortcut = { 'accueil': 'https://www.edenya.net/_vahal/' };
  221. localStorage.setItem('EdenyaShortcut', JSON.stringify(shortcut));
  222. localShortcut = localStorage.getItem('EdenyaShortcut');
  223. }
  224. var localShortcutParsed = JSON.parse(localShortcut);
  225.  
  226. var titre = document.createElement("p");
  227. var linkToAdd = document.createElement("span");
  228.  
  229. linkToAdd.innerHTML = "<a href='#'> Ajouter </a>";
  230. linkToAdd.setAttribute("onclick", "Valk_Add()");
  231. titre.innerText = "Raccourcis : ";
  232. titre.appendChild(linkToAdd);
  233. divScript.appendChild(titre);
  234. var menuToAdd = document.createElement("menu");
  235. menuToAdd.setAttribute("id","menuValk");
  236. divScript.appendChild(menuToAdd);
  237.  
  238. divScript.className = "cadre";
  239. divScript.style = "width:194";
  240. x.appendChild(divScript);
  241. titre = document.createElement("p");
  242. titre.innerText = "Couleurs utilisées :";
  243. divScript.appendChild(titre);
  244. // Refresh des raccourcis mémorisés
  245. Valk_Refresh();
  246.  
  247. var localTips = localStorage.getItem('EdenyaTips');
  248. if (localTips === null) {
  249. localTips = {};
  250. localTips.cadre2 = "Couleur générale titre, panneau PJ,...";
  251. localTips.ligneA = "Couleur texte hors balises RP";
  252. localTips.dialogue = "Texte d'un dialogue";
  253. localTips.narration = "Texte de narration";
  254. localTips.cri = "Texte crié";
  255. localTips.hj = "descriptions HJ";
  256. localTips.BlackDate = "couleur des dates dans les forums";
  257. localStorage.setItem('EdenyaTips', JSON.stringify(localTips));
  258. localTips = localStorage.getItem('EdenyaTips');
  259. }
  260. var localTipsParsed = JSON.parse(localTips);
  261.  
  262. for (item in localColorParsed) {
  263. var inputColor = document.createElement("input");
  264. inputColor.setAttribute("id", item);
  265. inputColor.setAttribute("type", "color");
  266. inputColor.setAttribute("class", "bouton");
  267. inputColor.setAttribute("value", localColorParsed[item]);
  268. inputColor.setAttribute("style", "width:25;padding:0");
  269. inputColor.setAttribute("onChange", "var z = localStorage.getItem('EdenyaColor');z = JSON.parse(z);z['" + inputColor.getAttribute("id") + "'] = document.getElementById('" + inputColor.getAttribute("id") + "').value; localStorage.setItem('EdenyaColor',JSON.stringify(z));location.href = location.href;");
  270. inputColor.setAttribute("onMouseOver", "ShowHelpTab('<b>Usage :</b><br>"+localTipsParsed[item]+"')");
  271. inputColor.setAttribute("onMouseOut", "HideHelp()");
  272. inputColor.title = localTipsParsed[item];
  273. divScript.appendChild(inputColor);
  274. }
  275. var localPreview = localStorage.getItem('EdenyaPreview');
  276. if(localPreview === null) {
  277. localPreview = true;
  278. localStorage.setItem('EdenyaPreview', localPreview);
  279. }
  280. var localPreviewParsed = JSON.parse(localPreview);
  281. var checkPreview = document.createElement("input");
  282. checkPreview.setAttribute("type","checkbox");
  283. checkPreview.checked = localPreviewParsed;
  284. checkPreview.setAttribute ("onclick", "localStorage.setItem('EdenyaPreview', !JSON.parse(localStorage.getItem('EdenyaPreview')));");
  285. var spanTmp = document.createElement("span");
  286. spanTmp.innerText = "Prévisualisation de post : ";
  287. spanTmp.appendChild(checkPreview);
  288. spanTmp.setAttribute('style', 'display:block;');
  289. divScript.appendChild(spanTmp);
  290. }
  291. x = document.getElementsByClassName("contenu");
  292. var zz = x[0].getElementsByClassName("cadre")[0];
  293. if(zz.width == "80%"){
  294. zz.style.height = "50px";
  295. }
  296. }
  297. if (locationPath[locationPath.length - 2] == "_vahal" && locationPath[locationPath.length - 1] == "vide.php" && ((document.getElementsByClassName("titre"))[0]).innerText == "Nouveau message" && JSON.parse(localStorage.getItem('EdenyaPreview'))){
  298. var boutonSubmit = document.getElementsByName('Submit')[0];
  299. var pParent = boutonSubmit.parentElement;
  300. var boutonPreview = document.createElement('button');
  301. boutonPreview.innerText = "Prévisualiser";
  302. boutonPreview.className = "bouton";
  303. boutonPreview.setAttribute("type", "button");
  304. pParent.appendChild(boutonPreview);
  305. var toAddTextarea = (document.getElementsByName('message')[0]).parentElement.parentElement.parentElement.parentElement.parentElement;
  306. var lineToDivide = document.createElement('hr');
  307. toAddTextarea.appendChild(lineToDivide);
  308. var elementToAdd = document.createElement('div');
  309. elementToAdd.setAttribute('id','previewText');
  310. elementToAdd.setAttribute("style","text-align:left;");
  311. toAddTextarea.appendChild(elementToAdd);
  312. var line2ToDivide = document.createElement('hr');
  313. toAddTextarea.appendChild(line2ToDivide);
  314. toAddTextarea.appendChild(pParent);
  315. boutonPreview.setAttribute("onclick","(document.getElementsByName('Submit')[0]).disabled = false;var initial_texte = ((document.getElementsByName('message'))[0]).value;var regexpOpen = /\\[(narration|dialogue|cri|hj|ecriture)\\]/g;var regexpClose = /\\[\\/(narration|dialogue|cri|hj|ecriture)\\]/g;var previsu_texte = initial_texte.replace(regexpOpen, '<span class=\\'$1\\'>');previsu_texte = previsu_texte.replace(regexpClose, '</span><!--$1-->');var regexpImg = /\\[img\\]([^\\[]*)\\[\\/img\\]/g;previsu_texte = previsu_texte.replace(regexpImg, '<img src=\\'$1\\' border=\\'0\\'\\/>');previsu_texte = previsu_texte.replace(/\\n/g, '<'+'br/>');document.getElementById('previewText').innerHTML = previsu_texte;");
  316. // boutonPreview.setAttribute("onclick","(var initial_texte = ((document.getElementsByName('message'))[0]).value;var regexpOpen = /\\[(narration|dialogue|cri|hj|ecriture)\\]/g;var regexpClose = /\\[\\/(narration|dialogue|cri|hj|ecriture)\\]/g;var previsu_texte = initial_texte.replace(regexpOpen, '<span class=\\'$1\\'>');previsu_texte = previsu_texte.replace(regexpClose, '</span><!--$1-->');var regexpImg = /\\[img\\]([^\\[]*)\\[\\/img\\]/g;previsu_texte = previsu_texte.replace(regexpImg, '<img src=\\'$1\\' border=\\'0\\'\\/>');previsu_texte = previsu_texte.replace(/\\n/g, '<'+'br/>');document.getElementById('previewText').innerHTML = previsu_texte;");
  317. }
  318. })();