Bandcamp: I'm Not A Fan

Removes playback limitation and dialog "The time has come to open thy heart/wallet"

目前為 2023-06-19 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name                  Bandcamp: I'm Not A Fan
// @name:ru               Bandcamp: Я не фанат
// @description           Removes playback limitation and dialog "The time has come to open thy heart/wallet"
// @description:ru        Снимает ограничение воспроизведений и убирает диалог "Пришло время открыть свое сердце/кошелек"
// @namespace             bc-inotafan.user.js
// @version               1.2.0
// @license               MIT
// @author                askornot
// @icon                  https://s4.bcbits.com/img/favicon/safari-pinned-tab.svg
// @match                 https://*.bandcamp.com/*
// @homepageURL           https://greasyfork.org/ru/scripts/438039-bandcamp-i-m-not-a-fan
// @supportURL            https://greasyfork.org/ru/scripts/438039-bandcamp-i-m-not-a-fan/feedback
// @grant                 none
// @run-at                document-start
// @compatible            chrome  Violentmonkey 2.14.0
// @compatible            firefox Greasemonkey 4.11
// @compatible            firefox Violentmonkey 2.14.0
// ==/UserScript==

function inject() {
  'use strict';

  const uncap = (o) => (o.is_capped = false);

  const protect = (...namespaces) => {
    for (const namespace of namespaces) {
      const names = Object.keys(namespace);
      for (const name of names) {
        const target = namespace[name];
        Object.freeze(target);
      }
    }
  };

  const freeze = (data) => {
    data.trackinfo.map(uncap);
    data.is_purchased = true;
    data.play_cap_data = {
      streaming_limits_enabled: false,
      streaming_limit: Infinity,
    };
    protect(data);
  };

  const patch = () => {
    if (!Object.prototype.hasOwnProperty.call(window, 'Player')) return false;

    const target = 'init';

    const descriptor = Object.getOwnPropertyDescriptor(Player, target);
    if (descriptor === void 0) {
      console.error(`Failed extract "${target}" descriptor of "Player"!`);
      return false;
    }

    Object.defineProperty(Player, target, {
      ...descriptor,
      value: function () {
        freeze(...arguments);
        return descriptor.value.apply(this, arguments);
      },
    });
    console.info('The injection was successful!');
    return true;
  };

  new MutationObserver((_, observer) => {
    if (patch()) observer.disconnect();
  }).observe(document.documentElement, {
    childList: true,
    subtree: true,
  });
}

(function (source) {
  (
    document.getElementsByTagName('head')[0] ||
    document.body ||
    document.documentElement
  ).appendChild(
    Object.assign(document.createElement('script'), {
      textContent: '(' + source.toString() + ')()',
    })
  );
})(inject);