aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/dashboard-common.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/dashboard-common.js')
-rw-r--r--src/js/dashboard-common.js83
1 files changed, 81 insertions, 2 deletions
diff --git a/src/js/dashboard-common.js b/src/js/dashboard-common.js
index ef24457..e34e18a 100644
--- a/src/js/dashboard-common.js
+++ b/src/js/dashboard-common.js
@@ -24,7 +24,86 @@
/******************************************************************************/
-uDom.onLoad(function() {
+self.uBlockDashboard = self.uBlockDashboard || {};
+
+/******************************************************************************/
+
+// Helper for client panes:
+// Remove literal duplicate lines from a set based on another set.
+
+self.uBlock.mergeNewLines = function(text, newText) {
+ var lineBeg, textEnd, lineEnd;
+ var line, hash, bucket;
+
+ // Step 1: build dictionary for existing lines.
+ var fromDict = Object.create(null);
+ lineBeg = 0;
+ textEnd = text.length;
+ while ( lineBeg < textEnd ) {
+ lineEnd = text.indexOf('\n', lineBeg);
+ if ( lineEnd === -1 ) {
+ lineEnd = text.indexOf('\r', lineBeg);
+ if ( lineEnd === -1 ) {
+ lineEnd = textEnd;
+ }
+ }
+ line = text.slice(lineBeg, lineEnd).trim();
+ lineBeg = lineEnd + 1;
+ if ( line.length === 0 ) {
+ continue;
+ }
+ hash = line.slice(0, 8);
+ bucket = fromDict[hash];
+ if ( bucket === undefined ) {
+ fromDict[hash] = line;
+ } else if ( typeof bucket === 'string' ) {
+ fromDict[hash] = [bucket, line];
+ } else /* if ( Array.isArray(bucket) ) */ {
+ bucket.push(line);
+ }
+ }
+
+ // Step 2: use above dictionary to filter out duplicate lines.
+ var out = [ '' ];
+ lineBeg = 0;
+ textEnd = newText.length;
+ while ( lineBeg < textEnd ) {
+ lineEnd = newText.indexOf('\n', lineBeg);
+ if ( lineEnd === -1 ) {
+ lineEnd = newText.indexOf('\r', lineBeg);
+ if ( lineEnd === -1 ) {
+ lineEnd = textEnd;
+ }
+ }
+ line = newText.slice(lineBeg, lineEnd).trim();
+ lineBeg = lineEnd + 1;
+ if ( line.length === 0 ) {
+ if ( out[out.length - 1] !== '' ) {
+ out.push('');
+ }
+ continue;
+ }
+ bucket = fromDict[line.slice(0, 8)];
+ if ( bucket === undefined ) {
+ out.push(line);
+ continue;
+ }
+ if ( typeof bucket === 'string' && line !== bucket ) {
+ out.push(line);
+ continue;
+ }
+ if ( bucket.indexOf(line) === -1 ) {
+ out.push(line);
+ /* continue; */
+ }
+ }
+
+ return text.trim() + '\n' + out.join('\n');
+};
+
+/******************************************************************************/
+
+(function() {
// Open links in the proper window
uDom('a').attr('target', '_blank');
uDom('a[href*="dashboard.html"]').attr('target', '_parent');
@@ -34,4 +113,4 @@ uDom.onLoad(function() {
.descendants('.whatisthis-expandable')
.toggleClass('whatisthis-expanded');
});
-});
+})();