Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android-webview/assets/inject.js

Issue 29361445: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: fixed 2 more members in AdblockEngine Created Dec. 16, 2016, 8:31 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: libadblockplus-android-webview/assets/inject.js
diff --git a/libadblockplus-android-webview/assets/inject.js b/libadblockplus-android-webview/assets/inject.js
new file mode 100644
index 0000000000000000000000000000000000000000..d6c4599f47e9bf5994a4be1ebd312916a49665c0
--- /dev/null
+++ b/libadblockplus-android-webview/assets/inject.js
@@ -0,0 +1,44 @@
+var hideElements = function()
+{
+ // no need to invoke if already invoked on another event
+ if ({{BRIDGE}}.isElementsHidden())
+ {
+ {{DEBUG}} console.log('already hidden, exiting');
+ return;
+ }
+
+ // hide using element visibility (to be replaced with script body)
+ {{HIDE}}
+
+ {{BRIDGE}}.setElementsHidden(true); // set flag not to do it again
+};
+
+if ({{BRIDGE}}.getAddDomListener() && document.readyState != 'complete')
+{
+ {{BRIDGE}}.setAddDomListener(false);
+
+ // onreadystatechange event
+ document.onreadystatechange = function()
+ {
+ {{DEBUG}} console.log('onreadystatechange() event fired (' + document.readyState + ')')
+ if (document.readyState == 'interactive')
+ {
+ hideElements();
+ }
+ }
+
+ // load event
+ window.addEventListener('load', function(event)
+ {
+ {{DEBUG}} console.log('load() event fired');
+ hideElements();
+ });
+
+ // DOMContentLoaded event
+ document.addEventListener('DOMContentLoaded', function()
+ {
+ {{DEBUG}} console.log('DOMContentLoaded() event fired');
+ hideElements();
+ }, false);
+
+};

Powered by Google App Engine
This is Rietveld