Code Monkey home page Code Monkey logo

piper's Introduction

PiPer

Adds Picture in Picture functionality to Safari for YouTube, Netflix, Amazon Video, Twitch, and more!

Screenshot of PiPer in action

Features

  • Adds a dedicated Picture in Picture button to the video player of supported sites
  • Button integrates seamlessly with the player including hover effects and tooltips
  • Supports closed captions in Picture and Picture mode
  • Free and open source

Installation

Get the latest release from the Safari Extension Gallery

...or live life on the edge with the latest development build (IMPORTANT: these builds do not update automatically!)

Supported sites

Changelog

You can find information about releases here

Development

Building

Prerequisites

  • Mac running macOS 10.12 Sierra or later

Build tools

For convenience the following Node.js tools have been packaged with nexe and included in this repository:

However it is recommended to install the latest versions with Node.js:

npm install -g csso-cli
npm install -g svgo
npm install -g xar-js
npm install -g google-closure-compiler-js

Additionally a reimplementation of the utility PlistBuddy used for automated build numbering is provided but it is advisable to download the original as part of Xcode or from Apple's Command Line Tools

Steps

  1. Clone the repository
  2. Run make.sh
    1. By default this builds the unoptimized and unpackaged development version into the ./out/ directory that can then be installed using Safari's Extension Builder
    2. Alternatively run ./make.sh -p release to build the optimized and packaged release version (note that packaging requires a private key)

Supporting a new site

If we wanted to support example.com with the source:

<div class="video-container">
  <video src="blob:http://example.com/342b3a13-c892-54ec-84f6-281579de03ab"></video>
  <div class="video-captions">
    Example caption
  </div>
  <div class="video-controls">
    <button class="control button-play">Play</button>
    <button class="control button-fullscreen">Fullscreen</button>
  </div>
</div>

We would start by adding a new entry in the resources object in main.js:

const resources = {
  ...
  'example' : {
    buttonParent: function() {
      // Returns the element that will contain the button
      return document.querySelector('.video-controls');
    },
    videoElement: function() {
      // Returns the video element
      return document.querySelector('.video-container video');
    },
    
    // Optional
    captionElement: function() {
      // Returns the element that contains the video captions
      return document.querySelector('.video-captions');
    },
  },
};

We also need to update the extension permissions to support the new site by editing ./src/Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Permissions</key>
  <dict>
    <key>Website Access</key>
    <dict>
      ...
      <key>Allowed Domains</key>
      <array>
        ...
        <string>example.com</string>
        <string>*.example.com</string>
      </array>
    </dict>
  </dict>
</dict>
</plist>

We might want to style the button so that it integrates with the page better:

const resources = {
  ...
  'example' : {
    ...
    // Assign a CSS class
    buttonClassName: 'control',
    // Scale the button
    buttonScale: 0.5,
    // Apply custom CSS styles
    buttonStyle: /** CSS */ (`
      /* Declaring CSS this way ensures it gets optimized when the extension is built */
      cursor: pointer;
      opacity: 0.5;
    `),
    // Apply a custom CSS hover style
    buttonHoverStyle: /** CSS */ (`opacity: 1 !important`),
  },
};

For more examples, please see the source

Acknowledgements

  • Pied PíPer for the original inspiration and the Netflix icon
  • Google for the Picture in Picture icon

piper's People

Contributors

amarcu5 avatar ascagnel avatar atkodev avatar demesne avatar

Watchers

Ties 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.