Jurisquare GM Script

Améliore le fonctionnement de Jurisquare (www.jurisquare.be)

  1. // ==UserScript==
  2. // @name Jurisquare GM Script
  3. // @version 2.4.1
  4. // @namespace RJ
  5. // @author Rafael Jafferali
  6. // @description Améliore le fonctionnement de Jurisquare (www.jurisquare.be)
  7. // @include http://www.jurisquare.be*
  8. // @run-at document-end
  9. // ==/UserScript==
  10. debugger;
  11. var PDF_ICON = "data:image/gif; base64,"
  12. + "R0lGODlhEAAQAPcAAFoAAGMAAHMYGG6Ov3KQv3KRv3aTvXqVu3uVvH6XulWAyFmBxliCxV2ExF6E"
  13. + "xGGIw2KJw2WKwmeLwWmMwWyOwIwACJQAAJwhIa0ACLUAAL05OZxCQr1KSr1SWsYAAM4ICM4QENYY"
  14. + "GM4pMd45OecIEPcQEPcYGO85OfcpKf8xOc5KSt5KStZja+dKSu9CSu9KSudaWu9SUu9SWudaY+dz"
  15. + "c+97e/9zc/8A/4KavIWdvoigwIuiwoyiwo+lxJGnxpKoxpWryJesyZmtypywzJ2xzaO20am71Ky+"
  16. + "1q/A2LPD2t6EhN61veeMjO+cnO+trdLi+tTj+tbk+tfl+9nm+9vn+9zo+97p++/W1ufv9+Dq/OHs"
  17. + "/OPt/OXu/Obv/Ojw/erx/evy/e3z/e/0/fD2/vL3/vT4/vX5/vf6/vn7/////xQCgBQCQBLtDNdN"
  18. + "rxQCgBEGqNdN4xQCgBLtFAAAAJEFyCJ8mBLt4JEFURQHqJEFbRLuOAAAABLtPAAAAJEFyFWi2BLu"
  19. + "CJEFURQHSBLtWAAAAJEFyFWi2BLuJJEFURQHSJEFbRLuaAAABAAAAOaERAAAAgAABAAAMAAAACJ8"
  20. + "oNSLsf3QAAAAMAAABBQAABLrmJD7bAAAIAAAAFWi4BLuOAAAAAAAIADwqgAAIAAAAAAAAJDnvJDV"
  21. + "hhLuCJD7bJD7cZDVhpDnvBQAABLt5JDnyBLujJDuGJD7eAH//wAABBLtaAAAABLujJDuGJEFcP//"
  22. + "/5EFbZEJvBQAAAAAAFWi4BLuSJEJklWi4AAAABLunN3tDt3tIGKmyAACvGKm1AAAAAAAAAAAAAAA"
  23. + "AAAAABLuaBLu7BSjUBSjUBLuoOb8I8OlLsYaoBLu2MLCzQAABMLC4xSo8BSjUAAAAxSgLcXS4BSg"
  24. + "ABLu1BLupP///xLvQMNclMEgcP///8LC40SV1RSjUGMboGMboEUEtRQAABSo8KR+UAAAAAAAAOqG"
  25. + "1OqG1OqG1OqG1AACXBLvJN1sdBLvLKR+UKR+UObgowAACeaCsAAABCH5BAEAADcALAAAAAAQABAA"
  26. + "AAjcAG8ITGKkCJEgPnbkSJBAoMMbSNCcMVOGzBgxCdI0fHhkYsWLYTJqvNGBgwYVM2DIgOFCBBiR"
  27. + "Gm28SIHChIkSJkhg+MKw54kQIEB4+OABQ4YKXrpw2aIlgYUAAARsmLrhwgalTLNsvDFETBgwX1Zg"
  28. + "1ZLFygGHQr5+uTKiSVYrVQw4BALWSw0sTJyUrUKFgMMfX7xcaeHEyYoWMZRMoeCwR1IYS8jCXcJC"
  29. + "igSHPLrMYCKZ7xQpUSA41EGDRmcqn6NAceAwx1vPoKE8WeAQBwIEBgoMmBDhQQMGChQEBAA7";
  30. var MOIS = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août",
  31. "septembre", "octobre", "novembre", "décembre"];
  32. var RG_counter = 0;
  33. // Taken from http://wiki.greasespot.net/Content_Script_Injection
  34. function InjectScript(source) {
  35. // Check for function input.
  36. if ('function' == typeof source) {
  37. // Execute this function with no arguments, by adding parentheses.
  38. // One set around the function, required for valid syntax, and a
  39. // second empty set calls the surrounded function.
  40. source = '(' + source + ')();'
  41. }
  42. // Create a script node holding this source code.
  43. var script = document.createElement('script');
  44. script.setAttribute("type", "application/javascript");
  45. script.textContent = source;
  46. // Insert the script node into the page, so it will run, and immediately
  47. // remove it to clean up.
  48. document.body.appendChild(script);
  49. document.body.removeChild(script);
  50. }
  51. function DefaultLibrarySearch() {
  52. InjectScript(function(){
  53. var LS = new LibrarySearch;
  54. LS.request.searchInOwnAssets = true;
  55. LS.request.order = "alpha";
  56. LS.pushState();
  57. location.reload();
  58. });
  59. }
  60. function ProcessResults(e) {
  61. try {var r = e.target.querySelector("h5") || e.target.querySelector("h1");} catch(err) {}
  62. if (r && r.querySelector("a") && r.querySelector("a").href) {
  63. var a = r.querySelector("a");
  64. var el = document.createElement("a");
  65. el.href = a.href.replace(/index\.html.*/, "document.pdf");
  66. el.target = "_blank";
  67. var img = document.createElement("img");
  68. img.src = PDF_ICON;
  69. img.style.paddingRight = "5px";
  70. el.appendChild(img);
  71. r.insertBefore(el, a);
  72. // Pasicrisie
  73. if (location.href.match(/pasicrisie/) && ( document.querySelector("div.filterlist a") || ( document.querySelector("span#resultCount") && document.querySelector("span#resultCount").textContent == "1" ) ) ) {
  74. // Filterlist vise à s'assurer que les filtres d'année ont déjà été appliqués, ou seulement un résultat
  75. if (document.querySelector("input.searchfield").value.match(/"\s\d+/)) { // Recherche par numéro à la Pasicrisie
  76. var num = document.querySelector("input.searchfield").value.match(/"\s\d+/).toString().match(/\d+/);
  77. if (a.innerText.search(num) >= 0) {
  78. location.href = el.href;
  79. }
  80. }
  81. else if (document.querySelector("input.searchfield").value.match(/"\s\w\.\d{2}\.\d{4}\.\w/)) { // Recherche par numéro de rôle
  82. if (window.self === window.top) {
  83. location.href = el.href;
  84. }
  85. else {
  86. window.top.postMessage(el.href, "http://jure.juridat.just.fgov.be/");
  87. }
  88. }
  89. GM_xmlhttpRequest({ // affichage des résumés
  90. method: "GET",
  91. url: a.href,
  92. onload: function(response) {
  93. var summary = response.responseText.match(/Résumé<\/p>[\s\S]*?<\/p>/).toString().match(/<p>[\s\S]+/).toString().replace(/<.?p>/g,"").replace(/^\s+|\s+$/g,"").replace(/\s\s*/g," ");
  94. r.nextElementSibling.innerText += "\n" + summary;
  95. }
  96. });
  97. }
  98. }
  99. }
  100. function addPasicrisieSearch() {
  101. var btn = document.createElement("input");
  102. btn.style.cssText = window.getComputedStyle(document.querySelector("input.searchbutton")).cssText;
  103. btn.type="submit";
  104. btn.value="Pasicrisie";
  105. if (!location.href.match(/content|library/)) {
  106. document.querySelector("input.searchfield").style.width = "403px";
  107. }
  108. document.querySelector("div.searchform").insertBefore(btn, document.querySelector("div.searchform div"));
  109. btn.addEventListener("click", function(){
  110. var d = document.querySelector("input.searchfield").value.replace(/\//g, "-");
  111. if (!location.href.match(/pasicrisie/)) {
  112. location.href = "http://www.jurisquare.be/fr/journal/pasicrisie/index.html#date" + d;
  113. }
  114. else {
  115. location.hash = "#date" + d;
  116. location.reload();
  117. }
  118. }, false);
  119. }
  120. function PasicrisieSearch() {
  121. // If called with the Pasicrisie button, fill in search field
  122. if (location.hash && location.hash.match(/date/)) {
  123. // Run search
  124. var d = location.hash.slice(5).split("-");
  125. var val = '"' + d[0].replace(/0(?=\d)/, "") + ( (d[0] == 1) ? "er" : "" ) + " " + MOIS[d[1].replace(/0(?=\d)/, "") - 1] + " " + d[2] + '"';
  126. if (d[3]) { val += " " + d[3]; }
  127. document.querySelector("input.searchfield").value = val;
  128. document.querySelector("input.searchbutton").click();
  129. }
  130. // If search is run with judgement date, select the year of the judgement as a filter
  131. if (!document.querySelector(".selected")) {
  132. var d = document.querySelector("input.searchfield").value.match(/"\d.+\s\d{4}"/);
  133. if (d) {
  134. function selectFilter(e) {
  135. if (e.target.querySelector("a").title == y) {
  136. e.target.querySelector("a").click();
  137. document.querySelectorAll("div.filterbox")[1].removeEventListener("DOMNodeInserted", selectFilter, false);
  138. }
  139. }
  140. // Set new filter
  141. var y = d.toString().match(/\d{4}/).toString();
  142. document.querySelectorAll("div.filterbox")[1].addEventListener("DOMNodeInserted", selectFilter, false);
  143. }
  144. }
  145. }
  146. function ShowDocOnly() {
  147. if (document.getElementById("the_canvas")) {
  148. var a = document.createElement("a");
  149. a.className = "greybutton";
  150. a.innerText = "Reading Mode";
  151. document.querySelector("div.detailhead").insertBefore(a, document.querySelector("a.back"));
  152. a.addEventListener("click", function() {
  153. document.body.removeChild(document.getElementById("headGutter"));
  154. document.querySelector("div.container_12").removeChild(document.querySelector("div.detailhead"));
  155. if (document.getElementById("sliderHolder")) {document.querySelector("div.container_12").removeChild(document.getElementById("sliderHolder"));}
  156. document.body.removeChild(document.getElementById("footGutter"));
  157. document.querySelector("div.container_12").style.marginLeft = 0;
  158. }, false);
  159. }
  160. }
  161. // MAIN
  162. if ( (window.self !== window.top) && (location.href == "http://www.jurisquare.be/fr/index.html")) {
  163. if (document.querySelector("input.button") && document.querySelector("input.button").value.match("log in")) {
  164. window.top.postMessage("LoginRequired", "http://jure.juridat.just.fgov.be/");
  165. }
  166. else {
  167. window.top.postMessage("LoginOkay", "http://jure.juridat.just.fgov.be/");
  168. }
  169. }
  170. if (location.href == "http://www.jurisquare.be/fr/library/index.html") {
  171. DefaultLibrarySearch();
  172. }
  173. if (document.querySelector("input.searchbutton") && document.querySelector("input.searchfield")) {
  174. addPasicrisieSearch();
  175. }
  176. if (document.getElementById("results")) {
  177. document.getElementById("results").addEventListener("DOMNodeInserted", ProcessResults, false);
  178. }
  179. if (location.href.match(/pasicrisie/)) {
  180. PasicrisieSearch();
  181. }
  182. ShowDocOnly();