Greasy Fork is available in English.

IMDb Actor Age redux

Display the actor's age next to movie credits.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
  1. // ==UserScript==
  2. // @name IMDb Actor Age redux
  3. // @namespace driver8.net
  4. // @description Display the actor's age next to movie credits.
  5. // @match *://*.imdb.com/name/nm*
  6. // @match *://*.imdb.com/title/tt*/
  7. // @match *://*.imdb.com/title/tt*/fullcredits*
  8. // @version 0.1.1
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js
  12. // ==/UserScript==
  13. console.log('hi imdb actor age');
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var LOGGING = false;
  19. function log(...msg) {
  20. LOGGING && console.log(...msg);
  21. }
  22.  
  23. /// ACTOR PAGES ///
  24. if (window.location.href.match(/\/name\/nm\d+\/(reference|\?|$)/)) {
  25. let actorNum = window.location.href.match(/\/name\/nm(\d+)/)[1];
  26. let birthday = document.querySelector('#name-born-info time');
  27. let birthTime = (birthday && birthday.textContent.trim()) || GM_getValue(actorNum);
  28. let birthMoment = moment(birthTime);
  29. log('birthTime', birthTime, 'mom', birthMoment);
  30.  
  31. if (birthTime) {
  32. GM_setValue(actorNum, birthMoment.format('YYYY-MM-DD'));
  33. if (birthday) {
  34. let ageSpan = getAgeSpan(birthMoment, moment());
  35. birthday.appendChild(ageSpan);
  36. }
  37. let yearCols = document.querySelectorAll('#filmography .year_column');
  38. yearCols.forEach((yc) => {
  39. log('yc', yc);
  40. let br = yc.parentNode.querySelector('br');
  41. let years = yc.textContent.trim();
  42. log('years', years);
  43. log('br', br)
  44. if (years && years.length > 3 && br) {
  45. let ageSpan = getAgeSpan(birthMoment, years);
  46. br.parentNode.insertBefore(ageSpan, br);
  47. }
  48. });
  49. }
  50.  
  51. /// MOVIE PAGES ///
  52. } else if (window.location.href.match(/\/title\/tt\d+\/(reference|fullcredits)?/)) {
  53. let rows = document.querySelectorAll('.StyledComponents__CastItemWrapper-y9ygcu-7, table.cast tr.odd, table.cast tr.even, table.cast_list tr.odd, table.cast_list tr.even');
  54. let m = document.title.match(/\((?:TV\s+(?:Series|Episode|Movie)\s*)?(\d{4}\s*(?:–|-)?\s*(?:\d{4})?)\s*\)/);
  55. if (m) {
  56. let titleYears = m[1];
  57. rows.forEach((el) => {
  58. log(el);
  59. let actorLink = el.querySelector('a');
  60. console.log(actorLink);
  61. let m = actorLink && actorLink.href.match(/\/name\/nm(\d+)/);
  62. if (m) {
  63. let actorNum = m[1];
  64. log(actorNum);
  65. let birthTime = GM_getValue(actorNum);
  66. log(birthTime);
  67. if (birthTime) {
  68. let ageSpan = getAgeSpan(moment(birthTime), titleYears);
  69. log(ageSpan);
  70. el.querySelectorAll('td > a, div > a')[1].after(ageSpan);//.appendChild(ageSpan);
  71. }
  72. }
  73. });
  74. }
  75. }
  76.  
  77. function getAgeSpan(birth, years) {
  78. log('getAgeSpan', birth, years);
  79. if (typeof years == "string") {
  80. var m = years.match(/(\d{4})(?:–|-)?(\d{4})?/);
  81. } else {
  82. m = [ years.format('YYYY-MM-dd') ];
  83. }
  84. log('match m', m, 'moment', moment(m[1]));
  85. let ageString = moment(m[1]).diff(birth, 'years');
  86. if (m[2]) {
  87. ageString += '-' + moment(m[2]).diff(birth, 'years');
  88. }
  89. ageString = '(age ' + ageString + ')';
  90. let ageSpan = document.createElement('span');
  91. ageSpan.classList.add('ageSpan');
  92. ageSpan.textContent = ageString;
  93. return ageSpan;
  94. }
  95.  
  96. function getFamousBirthday(name) {
  97. GM_xmlhttpRequest({
  98. method: 'GET',
  99. url: 'https://www.famousbirthdays.com/search?q=' + encodeURIComponent(name),
  100. onload: function(response) {
  101. var parser = new DOMParser();
  102. var h = parser.parseFromString(response.responseText, "text/html");
  103. var age = h.querySelector('').lastElementChild;
  104. var html = ``;
  105. var new_div = document.createElement('div');
  106. new_div.innerHTML = html;
  107. new_div = new_div.firstElementChild;
  108. document.querySelector('').insertBefore(new_div, document.querySelector(''));
  109. }
  110. });
  111. }
  112.  
  113. let s = document.createElement('style');
  114. s.textContent = `
  115. .ageSpan {
  116. font-size: 11px !important;
  117. font-weight: bold;
  118. }
  119. `;
  120. document.body.appendChild(s);
  121. })();