RT_Consensus

Adds RottenTomatoes Consensus under Google Knowledge Graph display

当前为 2014-08-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        RT_Consensus
// @namespace   none
// @author      n33t0r
// @description Adds RottenTomatoes Consensus under Google Knowledge Graph display
// @include     https://www.google.co.*/*
// @include     https://www.google.com/*
// @icon http://n33t0r.neocities.org/Tomato-256.png
// @version     0.3
// @grant       none
// ==/UserScript==
var start = function () {

  //var kng_check = document.getElementsByClassName('kp-blk _Rg _Ry _u2');
  var kng_check = document.getElementsByClassName('kp-blk _Jw _Rqb _LXc');
  if (kng_check.length) {
    var mov_check = document.querySelectorAll('div.ellip:nth-child(2) > span:nth-child(3) > a:nth-child(1)');
    if (mov_check.length) {
      var m_uri = mov_check[0].href;
      var base_uri = 'https://query.yahooapis.com/v1/public/yql?q=';
      var enc_muri = encodeURIComponent(m_uri);
      var query_url = 'select%20*%20from%20html%20where%20url%3D%22' + enc_muri + '%22%20and%20xpath%3D\'%2F%2F*%5B%40id%3D%22all-critics-numbers%22%5D%2Fdiv%2Fp\'&format=json&diagnostics=true';
      var fin_q = base_uri + query_url;
      var xhr = new XMLHttpRequest;
      if (!xhr) {
        console.error('Cant be created');
      }
      xhr.open('GET', fin_q, true);
      xhr.send();
      xhr.onreadystatechange = function () {
      if (xhr.readyState === 4) {
          if (xhr.status === 200) {
            var response = JSON.parse(xhr.responseText);
            add_data(response);
          } else {
            console.error('There was a problem with the request.');
          }
        }
      };
    }
  }
};
function add_data(data) {
  var consensus = data.query.results.p.content;
  var node = document.createTextNode(consensus);
  var el = document.createElement('div');
  root = document.querySelectorAll('.kno-rdesc');
  el.innerHTML += '<strong>Consensus: </strong>';
  el.appendChild(node);
  el.innerHTML += '<br><br>';
  root[0].insertBefore(el, root[0].firstChild);
}
start();