RT_Consensus

Adds RottenTomatoes Consensus under Google Knowledge Graph display

  1. // ==UserScript==
  2. // @name RT_Consensus
  3. // @namespace none
  4. // @author n33t0r
  5. // @description Adds RottenTomatoes Consensus under Google Knowledge Graph display
  6. // @include https://www.google.co.*/*
  7. // @include https://www.google.com/*
  8. // @icon http://n33t0r.neocities.org/Tomato-256.png
  9. // @version 0.3
  10. // @grant none
  11. // ==/UserScript==
  12. var start = function () {
  13.  
  14. //var kng_check = document.getElementsByClassName('kp-blk _Rg _Ry _u2');
  15. var kng_check = document.getElementsByClassName('kp-blk _Jw _Rqb _LXc');
  16. if (kng_check.length) {
  17. var mov_check = document.querySelectorAll('div.ellip:nth-child(2) > span:nth-child(3) > a:nth-child(1)');
  18. if (mov_check.length) {
  19. var m_uri = mov_check[0].href;
  20. var base_uri = 'https://query.yahooapis.com/v1/public/yql?q=';
  21. var enc_muri = encodeURIComponent(m_uri);
  22. 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';
  23. var fin_q = base_uri + query_url;
  24. var xhr = new XMLHttpRequest;
  25. if (!xhr) {
  26. console.error('Cant be created');
  27. }
  28. xhr.open('GET', fin_q, true);
  29. xhr.send();
  30. xhr.onreadystatechange = function () {
  31. if (xhr.readyState === 4) {
  32. if (xhr.status === 200) {
  33. var response = JSON.parse(xhr.responseText);
  34. add_data(response);
  35. } else {
  36. console.error('There was a problem with the request.');
  37. }
  38. }
  39. };
  40. }
  41. }
  42. };
  43. function add_data(data) {
  44. var consensus = data.query.results.p.content;
  45. var node = document.createTextNode(consensus);
  46. var el = document.createElement('div');
  47. root = document.querySelectorAll('.kno-rdesc');
  48. el.innerHTML += '<strong>Consensus: </strong>';
  49. el.appendChild(node);
  50. el.innerHTML += '<br><br>';
  51. root[0].insertBefore(el, root[0].firstChild);
  52. }
  53. start();