Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div>Drag the link to your bookmarks bar and click it.</div>
<details>
  <summary>Click here for Usage Help</summary>
  <p><b>Polling:</b> with polling turned on every 500 milliseconds it will search for new video elements on the page and will change their playback rates.</p>
  <p><b>Skip:</b> could be used to skip ads. Only works if the video is playing. Hasn't been tested on many videos.</p>
</details>
<video controls
    src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
    poster="https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217"
    width="620">

Sorry, your browser doesn't support embedded videos, 
but don't worry, you can <a href="https://archive.org/details/BigBuckBunny_124">download it</a> 
and watch it with your favorite video player!

</video>
              
            
!

CSS

              
                details {
  margin: 10px 0;
}



              
            
!

JS

              
                // edit main function and add all your javascript into it.
var nextId = idGen();
// you can edit this call to give your bookmarklet a different title and such
toBookmarklet({
  mainFn: main, 
  title: "Video Playback Rate Changer", 
  id: "bookmarklet1", 
  name: "Video Playback Rate Changer", 
  description: `Creates UI for changing Video Playback rates.`
});

async function main () {
  const mainId = "PlaybackChanger-v0-0-0";
  const getShadow = () => document.getElementById(mainId).shadowRoot;
  function log (...args) {
    window[mainId + "debugOn"] && console.log(...args);
  };
  const timeout = (ms) => {
    let id, reject;
    const p = new Promise((res,rej) => {
      reject = rej;
      id = setTimeout(res, ms);
    });
    p.clear = () => (clearTimeout(id), reject());
    return p;
  };
  function appendStyle (css) {
    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    getShadow().appendChild(style);
  }
  function AsyncLock() {
    const p = () => new Promise(next => (nextIter = next));
    var nextIter, next = p();
    const nextP = () => {
      const result = next;
      next = result.then(() => p());
      return result;
    };
    nextIter();
    return Object.assign(
      {},
      {
        async *[Symbol.asyncIterator]() {
          try {
            yield nextP();
          } finally {
            nextIter();
          }
        }
      }
    );
  }
  const pollLock = AsyncLock();
  async function* poller (ms=500) {
    for await (const _ of pollLock) {
      yield;
      while (true) {
        await timeout(ms);
        yield;
      }
    } 
  }
  async function changePlaybackRate (rate) {
    window[mainId + "currentPoller"] && window[mainId + "currentPoller"].return();
    const el = getShadow().getElementById("PlaybackRate");
    el.innerHTML = "";
    el.appendChild(document.createTextNode("" + rate.toFixed(2)));
    window[mainId + "currentPoller"] = poller();
    for await (const _ of window[mainId + "currentPoller"]) {
      log("changing video players to playback rate of: " + rate.toFixed(2));
      const videos = document.querySelectorAll("video");
      videos.forEach(v => {
        if(v.playbackRate != rate) {
          v.playbackRate = rate;
        }
      });
      if(!window[mainId + "pollingOpen"]) {
         return;
      }
    }
  }
  function getPlaybackRate () {
    const videos = document.querySelectorAll("video");
    const playingVid = [...videos].find(v => !v.paused);
    return window[mainId + "rate"] || Number(playingVid ? playingVid.playbackRate : videos[0] ? videos[0].playbackRate : 1);
  }
  const div = document.createElement("div");
  if(document.getElementById(mainId)) {
    document.getElementById(mainId).outerHTML = "";
  }
  document.body.appendChild(div);
  div.id = mainId;
  div.attachShadow({mode: 'open'}).innerHTML = `
    <div id="root">
    <h1 id="PlaybackRate">${getPlaybackRate().toFixed(2)}</h1>
    <input id="PlaybackSetter" type="range" value="${getPlaybackRate()}"" list="tickmarks" min="0.25" max="3" step="0.25">
    <div class="PlaybackCheckboxes">
      <label for="PlaybackPoll">Polling:</label><br/>
      <input id="PlaybackPoll" type="checkbox" ${window[mainId + "pollingOpen"]? "checked" : ""} />
    </div>
    <div class="PlaybackCheckboxes">
      <label for="PlaybackDebug">Debug:</label><br/>
      <input id="PlaybackDebug" type="checkbox" ${window[mainId + "debugOn"] ? "checked" : ""} />
    </div>
    <button id="${mainId}-skip">skip</button>
    <div id="${mainId}-close">X</div>
   </div>
  `;
  appendStyle(`
  #${mainId}-close {
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
  }

  #${mainId}-close:hover {
    color: #f0f0f0;
  }

  button {
    background-color: #f0f0f0;
    padding: 10px;
    color: black;
    border: 1px solid #ccc;
    border-radius: 3px;
  }

  button:hover {
    background-color: #fff;
    cursor: pointer;
  }

  #root {
    box-sizing: border-box;
    font-size: 10px;
    position: fixed;
    color: white;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    top: 0;
    right: 0;
    padding: 1em;
    opacity: 0.7;
    background-color: black;
    z-index: 99999;
    width: 500px;
    max-width: 100vw;
  }

  input[type=range] {
    -webkit-appearance: none; /* Hides the slider so that custom slider can be made */
    width: 100%; /* Specific width is required for Firefox. */
    background: transparent; /* Otherwise white in Chrome */
  }

  input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
  }

  input[type=range]:focus {
    outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
  }

  input[type=range]::-ms-track {
    width: 100%;
    cursor: pointer;

    /* Hides the slider so custom styles can be added */
    background: transparent; 
    border-color: transparent;
    color: transparent;
  }

  input[type='range'] {
    -webkit-appearance: none !important;
    background-color: #555;
    height: 7px;
    width: 100%;
    padding: 4px;
    border-radius: 3.5px;
  }

  input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none !important;
    height: 14px;
    width: 14px;
    border: 1px solid #ccc;
    -webkit-border-radius: 50%;
    border-radius: 50%;
    background-color: #fcfcfc;
  }

  /* All the same stuff for Firefox */
  input[type=range]::-moz-range-thumb {
    height: 14px;
    width: 14px;
    border: 1px solid #ccc;
    -webkit-border-radius: 50%;
    border-radius: 50%;
    background-color: #fcfcfc;
  }

  /* All the same stuff for IE */
  input[type=range]::-ms-thumb {
    height: 14px;
    width: 14px;
    border: 1px solid #ccc;
    -webkit-border-radius: 50%;
    border-radius: 50%;
    background-color: #fcfcfc;
  }

  #root > * {
    margin: 0 0.5em;
    flex: auto;
  }

  #root * {
    box-sizing: border-box;
    font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji" !important;
  }

  #PlaybackRate {
    font-size: 2.25em !important;
    font-weight: 800;
  }

  #PlaybackSetter {
    max-width: 100px;
    flex: 1 1 0;
    width: 100%;
    min-width: 50%; 
  }
  `);
  const shadowRoot = getShadow();
  const el = shadowRoot.getElementById("PlaybackSetter");
  let timer;
  el.addEventListener("input", async function (ev) {
    timer && timer.clear();
    const rate = Number(this.value);
    window[mainId + "rate"] = rate;
    changePlaybackRate(rate);
    try {
      timer = timeout(5000);
      await timer;
      document.getElementById(mainId).outerHTML = "";
    } catch (err) {
      console.error(err);
    }
  });
  shadowRoot.getElementById("PlaybackPoll").addEventListener("input", (ev) => {
    window[mainId + "pollingOpen"] = ev.target.checked;
    if(!window[mainId + "pollingOpen"]) {
      window[mainId + "currentPoller"] && window[mainId + "currentPoller"].return(); 
    } else {
      changePlaybackRate(window[mainId + "rate"]);
    }
  });
  shadowRoot.getElementById("PlaybackDebug").addEventListener("input", (ev) => {
    window[mainId + "debugOn"] = ev.target.checked;
  });
  shadowRoot.getElementById(`${mainId}-skip`).addEventListener("click", () => {
    const v = [...document.querySelectorAll("video")].find(v => !v.paused);
    if(v) { 
      v.currentTime = v.duration;
    }
  });
  shadowRoot.getElementById(`${mainId}-close`).addEventListener("click", () => {
    document.getElementById(mainId).outerHTML = "";
  });
}

// do not edit this function
function toBookmarklet (options) {
  const defaults = {
    mainFn: main,
    title: "", 
    id: nextId(), 
    name: "", 
    description: ""
  }
  options = $.extend({}, defaults, options);
  var {mainFn, title,id,name,description} = options;
  var html = $(`<div>
  <a id="link-${id}">${title}</a>
  <p>${description}</p>
  <textarea id="output-${id}"></textarea>
  <hr>
</div>`);
  var link = html.find(`#link-${id}`);
  link.attr("href", `
  javascript:
  (${mainFn.toString()})()
  `);
  html.find(`#output-${id}`).val((link[0] || {}).outerHTML);
  html.appendTo(document.body);
}

function idGen (id=0) {
  return ()=>id++;
}
              
            
!
999px

Console