Greasy Fork is available in English.

YouTube Auto Resume

Automatically continue watching YouTube videos on your favourite channels where you left off.

  1. // ==UserScript==
  2. // @name YouTube Auto Resume
  3. // @namespace https://greasyfork.org/en/users/68133-nevertheless
  4. // @version 1.34
  5. // @description Automatically continue watching YouTube videos on your favourite channels where you left off.
  6. // @author Nevertheless
  7. // @license MIT
  8. // @icon https://i.imgur.com/sGeEfkT.png
  9. // @match *://www.youtube.com/*
  10. // @exclude *://www.youtube.com/tv*
  11. // @exclude *://www.youtube.com/live_chat*
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @noframes
  15. // ==/UserScript==
  16.  
  17.  
  18. var doc = document;
  19. var win = window;
  20. if (win.frameElement) throw new Error("Stopped JavaScript.");
  21.  
  22. var style_basic = "\
  23. #btn-first {width:55px; height:38px; cursor:pointer; opacity:0.4;background-repeat:no-repeat; background-size:100%; background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAF0AAAA+CAYAAABJERc3AAAACXBIWXMAAA3XAAAN1wFCKJt4AAA52WlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4KPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMwNjcgNzkuMTU3NzQ3LCAyMDE1LzAzLzMwLTIzOjQwOjQyICAgICAgICAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWV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AgICAgICAgICAgICAgICAgPHN0RXZ0OndoZW4+MjAxOC0wMy0yM1QwMToxMTozNlo8L3N0RXZ0OndoZW4+CiAgICAgICAgICAgICAgICAgIDxzdEV2dDpzb2Z0d2FyZUFnZW50PkFkb2JlIFBob3Rvc2hvcCBDQyAyMDE1IChNYWNpbnRvc2gpPC9zdEV2dDpzb2Z0d2FyZUFnZW50PgogICAgICAgICAgICAgICAgICA8c3RFdnQ6Y2hhbmdlZD4vPC9zdEV2dDpjaGFuZ2VkPgogICAgICAgICAgICAgICA8L3JkZjpsaT4KICAgICAgICAgICAgPC9yZGY6U2VxPgogICAgICAgICA8L3htcE1NOkhpc3Rvcnk+CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24+CiAgICAgICAgIDx0aWZmOlhSZXNvbHV0aW9uPjkwMDAwMC8xMDAwMDwvdGlmZjpYUmVzb2x1dGlvbj4KICAgICAgICAgPHRpZmY6WVJlc29sdXRpb24+OTAwMDAwLzEwMDAwPC90aWZmOllSZXNvbHV0aW9uPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAgICA8ZXhpZjpDb2xvclNwYWNlPjY1NTM1PC9leGlmOkNvbG9yU3BhY2U+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj45MzwvZXhpZjpQaXhlbFhEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj42MjwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgIAo8P3hwYWNrZXQgZW5kPSJ3Ij8+TCGUbwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAGNklEQVR42uycS2gUdxzHP/+Z2Uey2c37sebhgxRLVKTUiPVsbakGK0ouWkWhCL4iClq9ehCqVipE8OClKIJSQg/iIV48KLQITQKiUq2iaDQPs3nva+bfwz9LojVmJdnZR+YLc9iZZfe/n/3N7zW/GbHth4MAPuBnoBkoAOKAxNFsJQADGAGuAUeBUQMIAJ3AIodRyuQF9gLfASsN4MxU4I55p8bcJ7QIOGMAmxJ7DCS9wmBQ6Lgc/LNWDEGhNCmX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B5ctw/jzUVIOeA2HFtFIAXQgYH4PwOOFvNxFdtAQRi07ro82RUbx11Xi3fv/hz9u+ncF/nxK6dh3XwoVZ6+stCT5do9htADLpByskB900YTDE0I+H6NvZPGP0jQPBmd7T1MTD63/gHhhGuLLzRmELsKTkc5+Xmnx30saTHPTxMeSCaoaavsGwQO+LgCamrfQNwFPiAn36/NtfV0txVTnxwWF0rycroQsgbEmeh2Ms8LjQtORuk0wOuuFCDI5g9PQyWlKIKJwekpzYrBlOBzMcJhKJYgmBlcWp5LhlUeE2FHDm0tK9Xujvo/SXM2j7jxIvLUNEp/fp8WicaHkB7lL/tB85/OdfaN2vya+tydqK1JIQcOt85vMos08yniYHXUoor8T16D4VLbuQlcGPFzujo0h/QI1J1FT//3h/PyVXLvNVdTmiyJfVRZNIuFkr+d+QfMpoxqG0HKJRxNv+j1unpiGe/AP796mr+KtXTx7r7ISTJzFevpy8cTabey/WpxvMpxVHUqruYDLZxuIlajBo7151V3RlJfT2KugeD9TW2n7/Zu63ARJ986IiePIE7t9XsINBVWiloY+d+9ATZ4amqatF7+93Gl6JvFPgskwwoziai/ZAFJdlIhAfhi4Ar7TocvlwC40B58Fps1axNOky8vBOeX5XAnoE8AugWMZpcxfym6cEw3lE4OzDGgK/NCmVccxJ7BEDuAHsBDAnniNYKE2H2Fx6mXfdyw0DOAJ8DSxIuBlHKdMr4IgB9APLgF+BLRMux4mkcyc3qvH6O9AChP4bAJlQEa9l14fSAAAAAElFTkSuQmCC'); }\
  24. #btn-first[resume] {opacity:1;}\
  25. #btn-first:hover {border-bottom: 2px solid #2a76f9;}\
  26. ";
  27.  
  28. function insertStyle(str, id) {
  29. var styleNode = null;
  30.  
  31. if (id != null) {
  32. styleNode = doc.getElementById(id);
  33. }
  34.  
  35. if (styleNode == null) {
  36. styleNode = newNode("style", id, null, doc.head);
  37. styleNode.setAttribute("type", "text/css");
  38. }
  39.  
  40. if (styleNode.textContent !== str)
  41. styleNode.textContent = str;
  42. }
  43.  
  44. insertStyle(style_basic, "ytctn_style_basic");
  45.  
  46. ytcontinue = {
  47. player: null,
  48. videoUrl: function() {
  49. if (typeof this.player === "undefined" || this.player === null) {
  50. return "";
  51. } else {
  52. return this.player.getVideoUrl();
  53. }
  54. },
  55. videoId: function() {
  56. if (typeof this.player === "undefined" || this.player === null) {
  57. return "";
  58. } else {
  59. return this.player.getVideoData().video_id;
  60. }
  61. },
  62. videoDuration: function() {
  63. if (typeof this.player === "undefined" || this.player === null) {
  64. return "";
  65. } else {
  66. return this.player.getDuration();
  67. }
  68. },
  69. initialResumeRequired: true,
  70. manualTimeJump: false,
  71. liveVideo: function() {
  72. if (typeof this.player === "undefined" || this.player === null) {
  73. return "";
  74. } else {
  75. return this.player.getVideoData().isLive;
  76. }
  77. },
  78. initialVideoId: "",
  79. interval: 3000,
  80. elapsed: 0,
  81. debug: true,
  82. actions: [],
  83. uiSet: false,
  84. saveAction: function(msg) {
  85. if (!this.debug)
  86. return;
  87. var msgwithtimestamp = new Date().toJSON() + " " + msg;
  88. this.actions.push(msgwithtimestamp);
  89. },
  90. viewActions: function() {
  91. for (var i in this.actions) {
  92. console.log('%c ' + this.actions[i], 'background: purple; color: white; display: inline;');
  93. }
  94. }
  95. };
  96.  
  97. function getPlayer() {
  98.  
  99. ytcontinue.elapsed += ytcontinue.interval;
  100. ytcontinue.saveAction("[Youtube Continue] getPlayer called.");
  101. ytcontinue.player = doc.getElementById("movie_player");
  102. if (typeof ytcontinue.player === "undefined" || ytcontinue.player === null) {
  103. ytcontinue.saveAction("[Youtube Continue] Player not defined.");
  104. return;
  105. }
  106. if (ytcontinue.liveVideo())
  107. return;
  108.  
  109. if (!ytcontinue.uiSet)
  110. buildUI();
  111.  
  112. if (ytcontinue.initialVideoId === "" || ytcontinue.videoId() !== ytcontinue.initialVideoId) {
  113. ytcontinue.initialVideoId = ytcontinue.videoId();
  114. ytcontinue.initialResumeRequired = true;
  115. ytcontinue.saveAction("[Youtube Continue] initialResumeRequired > true");
  116. toggle_resume("initialize");
  117. }
  118.  
  119. var qstr = getParameterByName('t');
  120. ytcontinue.manualTimeJump = (qstr !== null) && (qstr !== "0s");
  121.  
  122. if (ytcontinue.initialResumeRequired && ytcontinue.manualTimeJump !== true) {
  123. ytcontinue.saveAction("[Youtube Continue] resume called.");
  124. resumeVideo();
  125. } else {
  126. saveProgress();
  127. }
  128. }
  129.  
  130.  
  131. function resumeVideo() {
  132.  
  133. var ytcConfig = GM_getValue("ytcConfig", {});
  134.  
  135. if (typeof ytcConfig.channels === "undefined" || ytcConfig.channels === null) {
  136. ytcConfig.channels = {};
  137. GM_setValue("ytcConfig", ytcConfig);
  138. }
  139.  
  140. var channelName = ytcontinue.player.getVideoData().author;
  141.  
  142. if (typeof ytcConfig.channels[channelName] === "undefined" || ytcConfig.channels[channelName] === null) {
  143. return;
  144. }
  145.  
  146. var vidkey = "vid_" + ytcontinue.videoId();
  147.  
  148. var resume_to = ytcConfig.channels[channelName][vidkey];
  149. ytcontinue.saveAction("[Youtube Continue] progress read. > " + resume_to);
  150. var should_resume = true;
  151. video_duration = ytcontinue.videoDuration();
  152.  
  153. if (video_duration > 0) {
  154. should_resume = (video_duration - resume_to) >= video_duration * 0.05;
  155. ytcontinue.saveAction("[Youtube Continue] should_resume? > " + should_resume);
  156. }
  157.  
  158. var currentTime = ytcontinue.player.getCurrentTime();
  159.  
  160. if (currentTime >= resume_to || resume_to <= 0 || !should_resume) {
  161. ytcontinue.initialResumeRequired = false;
  162. } else {
  163. ytcontinue.player.seekTo(resume_to, true);
  164. ytcontinue.saveAction("[Youtube Continue] seekTo called. > " + resume_to);
  165. ytcontinue.initialResumeRequired = false;
  166. }
  167. }
  168.  
  169.  
  170. function saveProgress() {
  171. ytcontinue.saveAction("[Youtube Continue] saveProgress starts. > ");
  172.  
  173. var ytcConfig = GM_getValue("ytcConfig", {});
  174.  
  175. if (typeof ytcConfig.channels === "undefined" || ytcConfig.channels === null) {
  176. ytcConfig.channels = {};
  177. GM_setValue("ytcConfig", ytcConfig);
  178. }
  179.  
  180. var channelName = ytcontinue.player.getVideoData().author;
  181.  
  182. if (typeof ytcConfig.channels[channelName] === "undefined" || ytcConfig.channels[channelName] === null) {
  183. return;
  184. }
  185.  
  186.  
  187. var currPlaybackTime = ytcontinue.player.getCurrentTime();
  188. var vidkey = "vid_" + ytcontinue.videoId();
  189. should_resume = (ytcontinue.videoDuration() - currPlaybackTime) >= ytcontinue.videoDuration() * 0.05;
  190.  
  191. if (!should_resume) {
  192. delete ytcConfig.channels[channelName][vidkey];
  193. GM_setValue("ytcConfig", ytcConfig);
  194. return;
  195. }
  196.  
  197. ytcConfig.channels[channelName][vidkey] = currPlaybackTime;
  198. GM_setValue("ytcConfig", ytcConfig);
  199. ytcontinue.saveAction("[Youtube Continue] progress written. > " + currPlaybackTime);
  200. }
  201.  
  202. function newNode(kind, id, classname, refnode, position) {
  203.  
  204. var node = doc.createElement(kind);
  205.  
  206. if (node == null) return null;
  207.  
  208. if (id != null) node.id = id;
  209.  
  210. if (classname != null) node.className = classname;
  211.  
  212. if (refnode != null) {
  213. switch (position) {
  214. //insert after refnode
  215. case 'after':
  216. if (refnode.nextSibling != null)
  217. refnode.parentNode.insertBefore(node, refnode.nextSibling);
  218. else
  219. refnode.parentNode.appendChild(node);
  220. break;
  221.  
  222. //insert before refnode
  223. case 'before':
  224. refnode.parentNode.insertBefore(node, refnode);
  225. break;
  226.  
  227. //insert as first child of refnode
  228. case 'first':
  229. var child = refnode.childNodes[0];
  230. if (child != null)
  231. refnode.insertBefore(node, child);
  232. else
  233. refnode.appendChild(node);
  234. break;
  235.  
  236. //insert as last child of refnode
  237. case 'last':
  238. default:
  239. refnode.appendChild(node);
  240. break;
  241. }
  242. }
  243.  
  244. return node;
  245. }
  246.  
  247.  
  248.  
  249. function toggle_resume(initialize) {
  250. var ytcConfig = GM_getValue("ytcConfig", {});
  251.  
  252. if (typeof ytcConfig.channels === "undefined" || ytcConfig.channels === null) {
  253. ytcConfig.channels = {};
  254. }
  255. var channelName = ytcontinue.player.getVideoData().author;
  256. var channelResumeStatus = false;
  257.  
  258.  
  259. if (typeof ytcConfig.channels[channelName] === "undefined" || ytcConfig.channels[channelName] === null) {
  260. if (initialize != "initialize") {
  261. channelResumeStatus = true;
  262. ytcConfig.channels[channelName] = {};
  263. GM_setValue("ytcConfig", ytcConfig);
  264. } else {
  265. channelResumeStatus = false;
  266. }
  267. } else {
  268. if (initialize != "initialize") {
  269. channelResumeStatus = false;
  270. delete ytcConfig.channels[channelName];
  271. GM_setValue("ytcConfig", ytcConfig);
  272. } else {
  273. channelResumeStatus = true;
  274. }
  275. }
  276.  
  277.  
  278. var node = doc.getElementById('btn-first');
  279. if (node) {
  280. if (channelResumeStatus) {
  281. node.setAttribute("resume", "true");
  282. node.title = "Auto-Resume is ON for videos on this channel";
  283. } else {
  284. node.removeAttribute("resume");
  285. node.title = "Auto-Resume is OFF for videos on this channel";
  286. }
  287. }
  288. }
  289.  
  290. function getParameterByName(name, url) {
  291. if (!url) url = window.location.href;
  292. name = name.replace(/[\[\]]/g, "\\$&");
  293. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  294. results = regex.exec(url);
  295. if (!results) return null;
  296. if (!results[2]) return '';
  297. return decodeURIComponent(results[2].replace(/\+/g, " "));
  298. }
  299.  
  300. function buildUI() {
  301. var ytcontinuebtn = document.getElementById("btn-ytcontinue");
  302. if (typeof ytcontinuebtn === "undefined" || ytcontinuebtn === null) {
  303. var lmstate = document.getElementById("limited-state");
  304. if (typeof lmstate === "undefined" || lmstate === null)
  305. return;
  306.  
  307. var bgel = newNode("div", "btn-ytcontinue", null, lmstate, "after");
  308. bgel.setAttribute('style', "margin-top: 5px;height: 44px;");
  309. var btnel = newNode("div", "btn-first", null, bgel, "first");
  310. btnel.onclick = toggle_resume;
  311. toggle_resume("initialize");
  312. ytcontinue.uiSet = true;
  313. }
  314. }
  315.  
  316. win.setInterval(getPlayer, ytcontinue.interval);