Browse Source

finally added to git.

Jason Schwarzenberger 4 months ago
commit
d2d0fd9c77
8 changed files with 100 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 3 0
      .gitignore
  3. 21 0
      LICENSE
  4. 5 0
      README.md
  5. BIN
      img/icon-128.png
  6. 39 0
      inject.js
  7. 22 0
      manifest.json
  8. 8 0
      style.css

+ 2 - 0
.gitattributes

@@ -0,0 +1,2 @@
+# Auto detect text files and perform LF normalization
+* text=auto

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+# Ignore Mac system files
+.DS_store
+*.zip

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019 Jason
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 5 - 0
README.md

@@ -0,0 +1,5 @@
+# NZHerald Bypass
+
+Bypasses the new NZHerald Premium paywall using Javascript to peek at the LD+JSON Schema to figure out which CSS selector is being used to hide content.
+
+I made this mostly for myself.

BIN
img/icon-128.png


+ 39 - 0
inject.js

@@ -0,0 +1,39 @@
+(function() {
+  const ld = [].map
+    .call(document.querySelectorAll('script[type="application/ld+json"]'), e => {
+      try {
+        return JSON.parse(e.innerText);
+      } catch (e) {
+        return null;
+      }
+    })
+    .find(l => {
+      const notNull = l !== null;
+      const isSchema = l['@context'] === 'http://schema.org';
+      const isArticle = l['@type'] === 'Article';
+      const hasPart = l.hasOwnProperty('hasPart');
+      return notNull && isSchema && isArticle && hasPart;
+    });
+
+  const content = document.querySelector('.premium-content');
+
+  if (!ld || !content) {
+    return;
+  }
+
+  const selector = ld.hasPart.cssSelector;
+  const inserted = content.parentElement.insertBefore(content.cloneNode(true), content);
+  const [displayed, hidden] = [content, inserted];
+
+  displayed.style.marginBottom = '75px';
+  displayed.removeAttribute('id');
+  displayed.classList.replace('premium-content', 'content');
+  Array.from(displayed.querySelectorAll(selector)).forEach(e => {
+    e.classList.remove(selector.substring(1));
+    e.style = '';
+  });
+
+  hidden.style.opacity = 0.1;
+  hidden.style.height = '1px';
+  hidden.style.overflow = 'hidden';
+})();

+ 22 - 0
manifest.json

@@ -0,0 +1,22 @@
+{
+  "manifest_version": 2,
+  "name": "NZHerald Bypass",
+  "version": "1.1.5",
+  "description": "Improves the NZHerald experience",
+  "content_scripts": [
+    {
+      "js": [
+        "inject.js"
+      ],
+      "css": [
+        "style.css"
+      ],
+      "matches": [
+        "https://www.nzherald.co.nz/*"
+      ]
+    }
+  ],
+  "icons": {
+    "128": "img/icon-128.png"
+  }
+}

+ 8 - 0
style.css

@@ -0,0 +1,8 @@
+.premium-sub,
+.article-offer {
+  display: none !important;
+}
+
+.ellipsis:after {
+  content: None !important;
+}