Init Data

Get the Init Data you need.

  1. // ==UserScript==
  2. // @name Init Data
  3. // @namespace http://greasyfork.org/
  4. // @version 1.0
  5. // @description Get the Init Data you need.
  6. // @author X34Bruh
  7. // @match *://*/*
  8. // @run-at document-start
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (async () => {
  13. const indent = (s,n=4) => s.split('\n').map(l=>Array(n).fill(' ').join('')+l).join('\n');
  14.  
  15. const b64 = {
  16. decode: s => Uint8Array.from(atob(s), c => c.charCodeAt(0)),
  17. encode: b => btoa(String.fromCharCode(...new Uint8Array(b)))
  18. };
  19.  
  20. const fnproxy = (object, func) => new Proxy(object, { apply: func });
  21.  
  22. const proxy = (object, key, func) => Object.hasOwnProperty.call(object, key) && Object.defineProperty(object, key, {
  23. value: fnproxy(object[key], func)
  24. });
  25.  
  26. function messageHandler(event) {
  27. const keySession = event.target;
  28. const {sessionId} = keySession;
  29. const {message, messageType} = event;
  30. const listeners = keySession.getEventListeners('message').filter(l => l !== messageHandler);
  31. }
  32.  
  33. function keystatuseschangeHandler(event) {
  34. const keySession = event.target;
  35. const {sessionId} = keySession;
  36. const listeners = keySession.getEventListeners('keystatuseschange').filter(l => l !== keystatuseschangeHandler);
  37. }
  38.  
  39. function getEventListeners(type) {
  40. if (this == null) return [];
  41. const store = this[Symbol.for(getEventListeners)];
  42. if (store == null || store[type] == null) return [];
  43. return store[type];
  44. }
  45.  
  46. EventTarget.prototype.getEventListeners = getEventListeners;
  47.  
  48. typeof Navigator !== 'undefined' && proxy(Navigator.prototype, 'requestMediaKeySystemAccess', async (_target, _this, _args) => {
  49. const [keySystem, supportedConfigurations] = _args;
  50. return _target.apply(_this, _args);
  51. });
  52.  
  53. typeof MediaKeySystemAccess !== 'undefined' && proxy(MediaKeySystemAccess.prototype, 'createMediaKeys', async (_target, _this, _args) => {
  54. return _target.apply(_this, _args);
  55. });
  56.  
  57.  
  58. if (typeof MediaKeySession !== 'undefined') {
  59. proxy(MediaKeySession.prototype, 'generateRequest', async (_target, _this, _args) => {
  60. const [initDataType, initData] = _args;
  61. console.groupCollapsed(
  62. `[EME] MediaKeySession::generateRequest\n` +
  63. ` Session ID: ${_this.sessionId || '(not available)'}\n` +
  64. ` Init Data Type: ${initDataType}\n` +
  65. ` Init Data: ${b64.encode(initData)}`
  66. );
  67. console.trace();
  68. console.groupEnd();
  69. return _target.apply(_this, _args);
  70. });
  71.  
  72. }
  73. })();