dアニメストアが他の動画に紛れて表示されて釣られるので。

形式
JavaScript
投稿日時
2020-06-01 22:42
公開期間
無期限
  1. // ==UserScript==
  2. // @name channel_icon_over_thumbnail
  3. // @version 1
  4. // @grant GM.xmlHttpRequest
  5. // @include https://www.nicovideo.jp/*
  6. // @run-at document-start
  7. // ==/UserScript==
  8. // Copyright waived using CC0 1.0 Universal, 2020 dyknon
  9. function do_job(thumbnail){
  10. let link = thumbnail.parentNode;
  11. while(link && link.tagName != "A"){
  12. link = link.parentNode;
  13. }
  14. if(!link || link.host != "www.nicovideo.jp"){
  15. return;
  16. }
  17. let match = /^\/watch\/(([a-z]{2})[0-9]+)/.exec(link.pathname);
  18. if(!match || match[2] == "sm"){
  19. return;
  20. }
  21. let video_id = match[1];
  22. GM.xmlHttpRequest({
  23. method: "GET",
  24. url: "http://ext.nicovideo.jp/api/getthumbinfo/" + video_id,
  25. onload: res => {
  26. if(res.status != 200){
  27. return;
  28. }
  29. let p = new DOMParser();
  30. let doc = p.parseFromString(res.responseText, "application/xml");
  31. let iconurl_e = doc.querySelector(":root > thumb > ch_icon_url");
  32. if(!iconurl_e){
  33. return;
  34. }
  35. let channel_name_e = doc.querySelector(":root > thumb > ch_name");
  36. let icon_img = document.createElement("img");
  37. icon_img.style.position = "absolute";
  38. icon_img.style.right = "0";
  39. icon_img.style.top = "0";
  40. icon_img.style.width = "20%";
  41. icon_img.src = iconurl_e.textContent;
  42. if(channel_name_e){
  43. icon_img.alt = channel_name_e.textContent;
  44. }
  45. thumbnail.appendChild(icon_img);
  46. }
  47. });
  48. }
  49. function test_and_do_job(el){
  50. if(el.tagName != "DIV"){
  51. return;
  52. }
  53. let cl = el.classList;
  54. if(cl.contains("Thumbnail")){
  55. do_job(el);
  56. }
  57. }
  58. for(let thumbnail of document.querySelectorAll("div.Thumbnail")){
  59. do_job(thumbnail);
  60. }
  61. new MutationObserver((mu, obs)=>{
  62. for(let mr of mu){
  63. if(mr.type == "attributes"){
  64. test_and_do_job(mr.target);
  65. }else if(mr.type == "childList"){
  66. for(let el of mr.addedNodes){
  67. test_and_do_job(el);
  68. for(let thumbnail of el.querySelectorAll("div.Thumbnail")){
  69. do_job(thumbnail);
  70. }
  71. }
  72. }
  73. }
  74. }).observe(document, {childList: true, subtree: true, attributes: true, attributeFilter: ["class"]});
ダウンロード 印刷用表示

このコピペの URL

JavaScript での埋め込み

iframe での埋め込み

元のテキスト