brazil_senado_federal_ecidadania.user.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. // ==UserScript==
  2. // @namespace librecitizen
  3. // @version 1.1
  4. // @description Replacements for all JavaScript of the websites for Executive, Judiciary and Legislative government powers. Configure your browser to **disable** all JavaScript.
  5. // @description:pt-BR Substitutos a todo o JavaScript dos sites dos poderes Executivo, Judiciário e Legislativo. Configure teu navegador para **desativar** todo o JavaScript.
  6. // @name LibreCitizen: Brazil Senado Federal's e-Cidadania
  7. // @name:pt-BR LibreCitizen: e-Cidadania do Senado Federal do Brasil
  8. // @match *://www12.senado.leg.br/ecidadania*
  9. // @grant none
  10. // @require https://git.savannah.nongnu.org/cgit/userjs-common.git/plain/userjs-common.js?h=1.5
  11. // ==/UserScript==
  12. /*
  13. @source https://notabug.org/adfeno/librecitizen/archive/1.1.tar.gz
  14. @licstart The following is the entire license notice for the
  15. JavaScript code in this page.
  16. LibreCitizen: Replacements for all JavaScript of the websites for
  17. Executive, Judiciary and Legislative government powers.
  18. Copyright (C) 2019, 2021, 2024 Adonay Felipe Nogueira <https://libreplanet.org/wiki/User:Adfeno> <adfeno.7046@gmail.com>
  19. This file is part of LibreCitizen.
  20. LibreCitizen is free software: you can redistribute it and/or modify it
  21. under the terms of the GNU General Public License as published by the
  22. Free Software Foundation, either version 3 of the License, or (at your
  23. option) any later version.
  24. LibreCitizen is distributed in the hope that it will be useful, but
  25. WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. General Public License for more details.
  28. You should have received a copy of the GNU Affero General Public License
  29. along with LibreCitizen. If not, see <https://www.gnu.org/licenses/>.
  30. As additional permission under GNU GPL version 3 section 7, you may
  31. distribute non-source (e.g., minimized or compacted) forms of that code
  32. without the copy of the GNU GPL normally required by section 4, provided
  33. you include this license notice and a URL through which recipients can
  34. access the Corresponding Source.
  35. @licend The above is the entire license notice for the JavaScript code
  36. in this page.
  37. # Contact and contributing
  38. See <https://notabug.org/adfeno/librecitizen>.
  39. # Dependencies
  40. ## Common Userscript Definitions (userjs-common)
  41. Version: 1.5
  42. License: GPL-3.0-or-later
  43. Reference: https://git.savannah.nongnu.org/cgit/userjs-common.git/tag/?h=1.5
  44. There is no need to manually get this dependency since part of it will be
  45. downloaded through the @require property of this userscript's metadata
  46. block when installing it.
  47. */
  48. style_class_name = "librecitizen";
  49. document.head.appendChild(document.createElement("style")).innerText = `
  50. #portal-login,
  51. details > * {
  52. display: initial !important;
  53. }
  54. .collapse {
  55. border: initial !important;
  56. border-radius: initial !important;
  57. padding: initial !important;
  58. }
  59. `;
  60. window.onerror = alert;
  61. function set_csrf_protection_cookie() {
  62. /*
  63. Sets cookie for the cross-site request forgery (CSRF) protection token.
  64. */
  65. if (get_cookie("X-CSRF-TOKEN")) {
  66. return true;
  67. } else if (! document.querySelector('#protect-script')) {
  68. return false;
  69. }
  70. document.cookie = "X-CSRF-TOKEN=" +
  71. encodeURIComponent(document.querySelector('#protect-script')
  72. .getAttribute("data-token")) +
  73. ";" +
  74. "domain=" + document.location.host + ";" +
  75. "path=/ecidadania;" +
  76. "samesite=strict";
  77. return true;
  78. }
  79. function make_details_and_summary(selector_string) {
  80. document.querySelectorAll(selector_string).forEach(
  81. function replace_with_summary_and_details(anchor_element) {
  82. var old_detail_element =
  83. document.querySelector((new URL(anchor_element.href)).hash);
  84. var new_detail_element =
  85. clone_element_remvoing_event_handlers_and_listeners(
  86. old_detail_element,
  87. true
  88. );
  89. var details = new Map(
  90. [
  91. [
  92. "root",
  93. document.createDocumentFragment(),
  94. ],
  95. [
  96. "details",
  97. new Map(
  98. [
  99. [
  100. "root",
  101. document.createElement("details"),
  102. ],
  103. [
  104. "summary",
  105. new Map(
  106. [
  107. [
  108. "root",
  109. document.createElement("summary"),
  110. ],
  111. [
  112. "title",
  113. document.createElement("h2"),
  114. ],
  115. ]
  116. ),
  117. ],
  118. ]
  119. ),
  120. ],
  121. ]
  122. );
  123. details.get("details").get("summary").get("title").innerText =
  124. anchor_element.innerText;
  125. details.get("details").set(
  126. "content",
  127. new_detail_element
  128. );
  129. append_map_entries_to_root_node(details);
  130. old_detail_element.parentNode.replaceChild(
  131. details.get("root"),
  132. old_detail_element
  133. );
  134. remove_element(anchor_element);
  135. }
  136. );
  137. }
  138. async function get_comments_and_warnings() {
  139. var request = new Request(
  140. document.location.origin +
  141. "/ecidadania/ajaxcolecaocomentarioaudiencia" +
  142. "?" +
  143. "audienciaId=" +
  144. (new URLSearchParams(document.location.search)).get("id")
  145. );
  146. var response = await fetch(request);
  147. if (response.status == 200) {
  148. response = await response.text();
  149. var template = document.createElement("template");
  150. template.innerHTML = response;
  151. document.querySelector('#comentarios').appendChild(template.content);
  152. } else {
  153. console.debug(
  154. request,
  155. response,
  156. await response.text()
  157. );
  158. throw new Error(common_messages.error_unhandled_response_status);
  159. }
  160. var request = new Request(
  161. document.location.origin +
  162. "/ecidadania/ajaxmensagemavisoaudiencia" +
  163. "?" +
  164. "audienciaId=" +
  165. (new URLSearchParams(document.location.search)).get("id")
  166. );
  167. response = await fetch(request);
  168. if (response.status == 200) {
  169. response = await response.text();
  170. var template = document.createElement("template");
  171. template.innerHTML = response;
  172. document.querySelector('#box-aviso').appendChild(template.content);
  173. } else {
  174. console.debug(
  175. request,
  176. response,
  177. await response.text()
  178. );
  179. throw new Error(common_messages.error_unhandled_response_status);
  180. }
  181. }
  182. (async function keep_authenticated() {
  183. if (! set_csrf_protection_cookie()) {
  184. return false;
  185. }
  186. var request = new Request(
  187. document.location.origin +
  188. "/ecidadania/ajaxportaluser",
  189. {
  190. "method": "POST",
  191. }
  192. );
  193. var response = await fetch(request);
  194. if (response.status == 200) {
  195. // name: nome; login: e-mail
  196. response = await response.json();
  197. document.querySelector('#portal-login ins').innerText =
  198. response.name.toLowerCase();
  199. if (! localStorage.getItem("logged")) {
  200. localStorage.setItem("logged", "1");
  201. }
  202. } else {
  203. console.debug(
  204. request,
  205. response,
  206. await response.text()
  207. );
  208. throw new Error(common_messages.error_unhandled_response_status);
  209. }
  210. if (
  211. /^\/ecidadania\/visualizacaoaudiencia$/.test(document.location.pathname)
  212. ) {
  213. request = new Request(
  214. document.location.origin +
  215. "/ecidadania/ajaxautenticacaoaudiencia",
  216. {
  217. "method": "POST",
  218. "body": {
  219. "audienciaId": document.querySelector('#audienciaId').value,
  220. "_authenticator": document.querySelector('#_authenticator').value,
  221. },
  222. }
  223. );
  224. response = await fetch(request);
  225. if (response.status != 200) {
  226. console.debug(
  227. request,
  228. response,
  229. await response.text()
  230. );
  231. throw new Error(common_messages.error_unhandled_response_status);
  232. }
  233. }
  234. })();
  235. if (get_cookie("X-CSRF-TOKEN")) {
  236. for (let each_form of document.getElementsByTagName("FORM")) {
  237. var fragment_with_authentication_input =
  238. document.createDocumentFragment();
  239. var authentication_input = document.createElement("input");
  240. authentication_input.type = "hidden";
  241. authentication_input.name = "_authenticator";
  242. authentication_input.value = get_cookie("X-CSRF-TOKEN");
  243. fragment_with_authentication_input.appendChild(authentication_input);
  244. each_form.appendChild(fragment_with_authentication_input);
  245. }
  246. }
  247. if (/^\/ecidadania\/login(?:_form)?$/.test(document.location.pathname)) {
  248. var old_login_form = document.querySelector('#login_form');
  249. var new_login_form = clone_element_remvoing_event_handlers_and_listeners(
  250. old_login_form,
  251. true
  252. );
  253. document.querySelectorAll('.login-termo')
  254. .forEach(function add_term_to_login_form(old_term_element) {
  255. var new_term_element =
  256. clone_element_remvoing_event_handlers_and_listeners(
  257. old_term_element,
  258. true
  259. );
  260. new_term_element.querySelectorAll('input[type="checkbox"]')
  261. .forEach(function make_checkbox_required(input_checkbox) {
  262. input_checkbox.required = true;
  263. });
  264. new_login_form.querySelector('.formControls').parentNode.insertBefore(
  265. new_term_element,
  266. new_login_form.querySelector('.formControls')
  267. );
  268. remove_element(old_term_element);
  269. });
  270. old_login_form.parentNode.replaceChild(
  271. new_login_form,
  272. old_login_form
  273. );
  274. } else if (/^\/ecidadania\/logged_out$/.test(document.location.pathname)) {
  275. document.cookie = "X-CSRF-TOKEN=;" +
  276. "domain=" +
  277. document.location.host +
  278. ";" +
  279. "expires=" +
  280. (new Date(Date.now() - 1 * 1000)).toUTCString() +
  281. ";" +
  282. "path=/ecidadania;" +
  283. "samesite=strict";
  284. localStorage.removeItem("logged");
  285. } else if (
  286. /^\/ecidadania\/visualizacaoaudiencia$/
  287. .test(document.location.pathname)
  288. ) {
  289. get_comments_and_warnings();
  290. document.querySelectorAll('#div-comentarios form')
  291. .forEach(function replace_comment_form(old_comment_form) {
  292. new_comment_form = clone_element_remvoing_event_handlers_and_listeners(
  293. old_comment_form,
  294. true
  295. );
  296. new_comment_form.method = "post";
  297. new_comment_form.action = "ajaxcomentarioaudiencia";
  298. new_comment_form.querySelector('#comentario').name =
  299. new_comment_form.querySelector('#comentario').id;
  300. new_comment_form.querySelector('#comentario').setAttribute(
  301. "maxlength",
  302. 140
  303. );
  304. new_comment_form.querySelector('#btn-enviar').type = "submit";
  305. var audience_identity_hidden_input = document.createElement("input");
  306. audience_identity_hidden_input.type = "hidden";
  307. audience_identity_hidden_input.name = "audienciaId";
  308. audience_identity_hidden_input.value =
  309. (new URLSearchParams(document.location.search)).get("id");
  310. new_comment_form.appendChild(audience_identity_hidden_input);
  311. old_comment_form.parentNode.replaceChild(
  312. new_comment_form,
  313. old_comment_form
  314. );
  315. });
  316. document.querySelectorAll('.link-declaracao-participacao')
  317. .forEach(function replace_declaration_element(old_declaration_element) {
  318. new_declaration_element = new Map(
  319. [
  320. [
  321. "root",
  322. document.createDocumentFragment(),
  323. ],
  324. [
  325. "form",
  326. new Map(
  327. [
  328. [
  329. "root",
  330. document.createElement("form"),
  331. ],
  332. [
  333. "audience_identity",
  334. document.createElement("input"),
  335. ],
  336. [
  337. "submit_input",
  338. document.createElement("input"),
  339. ],
  340. ]
  341. ),
  342. ],
  343. ]
  344. );
  345. new_declaration_element.get("form").get("root").action =
  346. "declaracaoparticipacaoaudiencia";
  347. new_declaration_element.get("form").get("audience_identity").name =
  348. "audienciaId";
  349. new_declaration_element.get("form").get("audience_identity").type =
  350. "hidden";
  351. new_declaration_element.get("form").get("audience_identity").value =
  352. (new URLSearchParams(document.location.search)).get("id");
  353. new_declaration_element.get("form").get("submit_input").type =
  354. "submit";
  355. new_declaration_element.get("form").get("submit_input").value =
  356. old_declaration_element.innerText;
  357. if (
  358. ! localStorage.getItem("logged") ||
  359. (
  360. localStorage.getItem("logged") &&
  361. document.querySelector('#situacaoId:not([value="4"])')
  362. )
  363. ) {
  364. new_declaration_element.get("form").get("submit_input").disabled =
  365. true;
  366. }
  367. append_map_entries_to_root_node(new_declaration_element);
  368. old_declaration_element.parentNode.replaceChild(
  369. new_declaration_element.get("root"),
  370. old_declaration_element
  371. );
  372. });
  373. make_details_and_summary('#audiencia a.collapsed');
  374. } else if (
  375. /^\/ecidadania\/visualizacaoideia$/
  376. .test(document.location.pathname)
  377. ) {
  378. document.querySelectorAll('#barra-voto > .btn.ideia-btn-apoio')
  379. .forEach(function replace_unstandardized_support_button(old_button) {
  380. var new_button = new Map(
  381. [
  382. [
  383. "root",
  384. document.createDocumentFragment(),
  385. ],
  386. [
  387. "form",
  388. new Map(
  389. [
  390. [
  391. "root",
  392. document.createElement("form"),
  393. ],
  394. [
  395. "authenticator",
  396. document.querySelector('[name="_authenticator"]'),
  397. ],
  398. [
  399. "idea_identity",
  400. document.createElement("input"),
  401. ],
  402. [
  403. "submit_input",
  404. document.createElement("input"),
  405. ],
  406. ]
  407. ),
  408. ],
  409. ]
  410. );
  411. if (! new_button.get("form").get("authenticator")) {
  412. throw new Error("Não autenticado!");
  413. }
  414. new_button.get("form").set(
  415. "authenticator",
  416. new_button.get("form").get("authenticator").cloneNode(true)
  417. );
  418. new_button.get("form").get("root").method = "post";
  419. new_button.get("form").get("root").action =
  420. "ajaxapoiamentoideia";
  421. new_button.get("form").get("idea_identity").name =
  422. "id";
  423. new_button.get("form").get("idea_identity").type =
  424. "hidden";
  425. new_button.get("form").get("idea_identity").value =
  426. (new URLSearchParams(document.location.search)).get("id");
  427. new_button.get("form").get("submit_input").type =
  428. "submit";
  429. new_button.get("form").get("submit_input").value =
  430. old_button.innerText;
  431. append_map_entries_to_root_node(new_button);
  432. old_button.parentNode.replaceChild(
  433. new_button.get("root"),
  434. old_button
  435. );
  436. });
  437. make_details_and_summary('#ideia-legislativa a.collapsed');
  438. } else if (
  439. /^\/ecidadania\/visualizacaomateria$/
  440. .test(document.location.pathname)
  441. ) {
  442. var old_form;
  443. if (old_form = document.querySelector('#barra-voto')) {
  444. var new_form = new Map(
  445. [
  446. [
  447. "root",
  448. document.createDocumentFragment(),
  449. ],
  450. [
  451. "form",
  452. new Map(
  453. [
  454. [
  455. "root",
  456. document.createElement("form"),
  457. ],
  458. [
  459. "authenticator",
  460. document.querySelector('[name="_authenticator"]'),
  461. ],
  462. [
  463. "subject_identity",
  464. document.createElement("input"),
  465. ],
  466. ]
  467. ),
  468. ],
  469. ]
  470. );
  471. if (! new_form.get("form").get("authenticator")) {
  472. throw new Error("Not authenticated!");
  473. }
  474. new_form.get("form").set(
  475. "authenticator",
  476. new_form.get("form").get("authenticator").cloneNode(true)
  477. );
  478. new_form.get("form").get("root").method = "post";
  479. new_form.get("form").get("root").action = "ajaxapoiamentomateria";
  480. new_form.get("form").get("subject_identity").name = "materiaId";
  481. new_form.get("form").get("subject_identity").type = "hidden";
  482. new_form.get("form").get("subject_identity").value =
  483. (new URLSearchParams(document.location.search)).get("id");
  484. old_form.querySelectorAll('.btn[data-voto]')
  485. .forEach(function get_old_vote_button(old_button) {
  486. new_form.get("form").set(
  487. old_button.getAttribute("data-voto"),
  488. document.createElement("input")
  489. );
  490. new_form.get("form").set(
  491. old_button.getAttribute("data-voto") +
  492. "_label",
  493. document.createElement("label")
  494. );
  495. new_form.get("form").get(old_button.getAttribute("data-voto")).id =
  496. old_button.getAttribute("data-voto");
  497. new_form.get("form").get(old_button.getAttribute("data-voto")).name =
  498. "voto";
  499. new_form.get("form").get(old_button.getAttribute("data-voto")).type =
  500. "radio";
  501. new_form.get("form").get(old_button.getAttribute("data-voto")).value =
  502. old_button.getAttribute("data-voto");
  503. new_form.get("form").get(
  504. old_button.getAttribute("data-voto") +
  505. "_label"
  506. ).setAttribute(
  507. "for",
  508. old_button.getAttribute("data-voto")
  509. );
  510. new_form.get("form").get(
  511. old_button.getAttribute("data-voto") +
  512. "_label"
  513. ).innerText = old_button.innerText;
  514. });
  515. new_form.get("form").set(
  516. "submit_input",
  517. document.createElement("input")
  518. );
  519. new_form.get("form").get("submit_input").type = "submit";
  520. new_form.get("form").get("submit_input").value = common_messages.submit;
  521. append_map_entries_to_root_node(new_form);
  522. old_form.parentNode.replaceChild(
  523. new_form.get("root"),
  524. old_form
  525. );
  526. }
  527. make_details_and_summary(
  528. '#materia-legislativa a[data-toggle="collapse"], ' +
  529. '.materia-ementaExplicacao a[data-toggle="collapse"]'
  530. );
  531. }