Pinterest - Remove Promoted

Remove promoted pins

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Pinterest - Remove Promoted
// @namespace    https://github.com/valacar
// @version      0.1.0
// @description  Remove promoted pins
// @author       Valacar
// @include      https://*.pinterest.tld/*
// @require      https://unpkg.com/[email protected]/dist/xhook.min.js
// @grant        none
// @license      MIT
// ==/UserScript==

/* 3rd party script to modify XHR responses: https://github.com/jpillora/xhook */

(function() {
  "use strict";

  function isGoodPin(data) {
    return !(data.is_promoted && data.is_promoted === true)
  }

  function jsonFilter(response, isSearchResults) {
    let json = JSON.parse(response.text);
    let data;
    if (isSearchResults) {
      data = json.resource_response.data.results;
      json.resource_response.data.results = data.filter(isGoodPin);
    } else {
      data = json.resource_response.data;
      json.resource_response.data = data.filter(isGoodPin);
    }
    return JSON.stringify(json);
  }

  xhook.after(function(request, response) {
    if (request.url.match(/\/resource\/(UserHomefeedResource|FollowingFeedResource|RelatedModulesResource|BoardContentRecommendationResource|BoardFeedResource)\/get\//)) {
      response.text = jsonFilter(response, false);
    } else if (request.url.match(/\/resource\/BaseSearchResource\/get\//)) {
      response.text = jsonFilter(response, true);
    }
  });

})();