Code Monkey home page Code Monkey logo

privatkopiera's Introduction

Website: https://stefansundin.github.io/privatkopiera/

Chrome Web Store: https://chromewebstore.google.com/detail/privatkopiera/jhjhnecocacdbhlkjgpdacoibidhmgdf

Firefox Addons: https://addons.mozilla.org/addon/privatkopiera/

Icon: https://commons.wikimedia.org/wiki/File:VHS_diagonal.svg

Development

The extension directory contains the source code, which you can load directly in Chrome.

The firefox directory contains modifications necessary for the extension to run in Firefox (currently only the manifest file is different). You must run ./make-xpi.sh to copy over the other files, after which you can load the extension in about:debugging.

Bootstrap

To build the custom Bootstrap theme you need Node.js installed and then you can run:

cd bootstrap
npm install
npm run build

If you don't have Node.js or you don't want it, then you can get the default Bootstrap theme by running:

curl -f -o extension/css/bootstrap.min.css https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css

Or just download the file and put it there manually.

Formatting

The JavaScript code is formatted with prettier. The HTML is formatted with the built-in VS Code formatter.

Why are there more executeScript calls than seems necessary?

The extension performs all of its network requests through the host page, using chrome.scripting.executeScript(), for a number of reasons:

  1. Any POST request made in the extension will cause Chrome to add an Origin: chrome-extension://jhjhnecocacdbhlkjgpdacoibidhmgdf header. This header is easy to detect and block by websites (see #185). By making the network request from the host page instead, the Origin header will look normal from the website's point of view. There's a Chrome bug about this.
  2. The extension can avoid asking for host permissions when the user uses Privatkopiera on a website for the first time. This makes for a better experience since granting new permissions is not foolproof and at least one user reported that they didn't understand how to proceed (see #184).
  3. Some websites have permissive CORS permissions initially, but then later make it more restrictive. This makes for an impossible situation since the only workaround would be to ask for host permissions prematurely, even though they may not be required at the time.

executeScript error handling

Firefox has better error handling in its chrome.scripting.executeScript() implementation and populates an error key in the InjectionResult if an error was raised in the script. An issue has been filed to hopefully get the same support in Chrome.

Due to this, where appropriate, return values from executeScript are an object with result or error keys depending on what happened. The complicated scripts are also wrapped in a try-catch clause. This looks funky but will have to do until the situation in Chrome improves.

privatkopiera's People

Contributors

stefansundin avatar larsabrasha avatar nikteg avatar viktorlindgren avatar simnka avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.