From 14bed707e5c9891d4502e276a757bbef014e6b4e Mon Sep 17 00:00:00 2001
From: hackademix
Date: Fri, 22 Feb 2019 00:41:05 +0100
Subject: Deduplicate inline scripts and provide widgets to show them in main
UI.
---
html/display_panel/content/display-panel.html | 4 +++-
html/display_panel/content/main_panel.js | 11 ++++++++++-
html/display_panel/content/panel-styles.css | 14 ++++++++++++++
3 files changed, 27 insertions(+), 2 deletions(-)
(limited to 'html/display_panel')
diff --git a/html/display_panel/content/display-panel.html b/html/display_panel/content/display-panel.html
index 0e4df97..5eccf60 100644
--- a/html/display_panel/content/display-panel.html
+++ b/html/display_panel/content/display-panel.html
@@ -73,7 +73,8 @@
diff --git a/html/display_panel/content/main_panel.js b/html/display_panel/content/main_panel.js
index 7934fee..60eae55 100644
--- a/html/display_panel/content/main_panel.js
+++ b/html/display_panel/content/main_panel.js
@@ -55,6 +55,10 @@ liTemplate.remove();
document.querySelector("#info").addEventListener("click", e => {
let button = e.target;
+ if (button.matches(".toggle-source")) {
+ let sourceContainer = button.parentNode.querySelector(".source").classList.toggle("visible");
+ return;
+ }
if (!button.matches(".buttons > button")) return;
let li = button.closest("li");
let entry = li && li._scriptEntry || [currentReport.url, "Page's site"];
@@ -111,7 +115,7 @@ function createList(data, group){
container.classList.add("empty");
}
// generate list
- let viewSourceToHuman = /^view-source:(.*)#line(\d+)\(([^)]*)\).*/;
+ let viewSourceToHuman = /^view-source:(.*)#line(\d+)\(([^)]*)\)[^]*/;
for (let entry of entries) {
let [scriptId, reason] = entry;
let li = liTemplate.cloneNode(true);
@@ -119,6 +123,11 @@ function createList(data, group){
a.href = scriptId.split("(")[0];
if (scriptId.startsWith("view-source:")) {
a.target ="LibreJS-ViewSource";
+ let source = scriptId.split("\n")[1];
+ if (source) {
+ li.querySelector(".source").textContent = decodeURIComponent(source);
+ li.querySelector(".toggle-source").style.display = "inline";
+ }
scriptId = scriptId.replace(viewSourceToHuman, "$3 at line $2 of $1");
}
a.textContent = scriptId;
diff --git a/html/display_panel/content/panel-styles.css b/html/display_panel/content/panel-styles.css
index d5c3528..1bacc01 100644
--- a/html/display_panel/content/panel-styles.css
+++ b/html/display_panel/content/panel-styles.css
@@ -109,6 +109,20 @@ button:disabled {
color: #888 !important;
}
+button.toggle-source {
+ display: none;
+}
+pre.source {
+ display: none;
+ background: white;
+ border: 1px solid #444;
+ padding: .5em;
+ overflow: auto;
+ max-height: 8em;
+ white-space: pre-wrap;
+}
+pre.source.visible { display: block }
+
span.accepted, span.blocked {
color:#008e00;
font-size:145%;
--
cgit v1.2.3