Google productID from FC2,FANZA

replace pID to hyperLink

  1. // ==UserScript==
  2. // @name Google productID from FC2,FANZA
  3. // @version 0.1
  4. // @description replace pID to hyperLink
  5. // @author SWIU
  6. // @match https://adult.contents.fc2.com/article/*
  7. // @match https://www.dmm.co.jp/*/detail/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=dmm.co.jp
  9. // @run-at document-start
  10. // @namespace https://greasyfork.org/users/1196626
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. document.addEventListener(`DOMContentLoaded`, doAll, { once: true });
  16. const additionalWords = ` jav -site:www.dmm.co.jp -site:javtrailers.com -site:adult.contents.fc2.com -site:twitter.com -site:www.mgstage.com -site:duga.jp `;
  17. let cid = { raw: null, formatted: null }, productName, productNameElm, siteName = checkDomain();
  18.  
  19. async function doAll() {
  20. for (const func of [replaceProductName, replacecid]) {
  21. try {
  22. func.call();
  23. } catch (e) {
  24. console.log(e);
  25. }
  26. }
  27. }
  28.  
  29. function replaceProductName() {
  30. if (siteName === `FANZA`) {
  31. productNameElm = document.querySelector(`#title`);
  32. productName = productNameElm.textContent;
  33. } else if (siteName === `FC2`) {
  34. const _productNameElm = document.querySelector(`.items_article_headerInfo h3`);
  35. [..._productNameElm.childNodes].map(e => e.nodeName === `#text` && e.remove());
  36. productNameElm = document.createElement(`span`);
  37. _productNameElm.appendChild(productNameElm);
  38. productName = document.title.match(/(.+) /)[1];
  39. }
  40. const query = `${productName} ${additionalWords}`;
  41. const hyperlinkedElm = createLink(query, productName);
  42. console.log(productNameElm, hyperlinkedElm);
  43. productNameElm.replaceWith(hyperlinkedElm);
  44. productNameElm = hyperlinkedElm.parentElement;
  45. }
  46.  
  47. async function replacecid() {
  48. let cidElm, query;
  49. if (siteName === `FANZA`) {
  50. cidElm = [...document.querySelectorAll(`.nw`)].find(e => e.textContent.includes(`品番:`)).nextElementSibling;
  51. cid.raw = cidElm.textContent.trim();
  52. cid.formatted = formatcid(cid.raw);
  53. query = cid.formatted ? `"${cid.raw}" OR "${cid.formatted}"` : cid.raw;
  54.  
  55. function formatcid(rawcode) {
  56. let cidFormatMatch = rawcode.match(/(\D+)(\d+\D?)$/);
  57. const charPart = cidFormatMatch[1].toUpperCase();
  58. const numPart = cidFormatMatch[2].padStart(5, 0).replace(/^00/, ``);
  59. return `${charPart}-${numPart}`;
  60. }
  61. } else if (siteName === `FC2`) {
  62. cid.raw = document.querySelector(`title`).textContent.split(` `).at(-1).split(`-`).at(-1);
  63. cid.formatted = document.title.split(` `).at(-1);
  64. productNameElm.insertAdjacentHTML(`afterend`, `<div>品番:<span id="ftzcid">${cid.formatted}</span></div>`);
  65. cidElm = document.querySelector(`#ftzcid`);
  66. query = `"${cid.raw}" OR "${cid.formatted}"`;
  67. }
  68. const hyperlinkedElm = createLink(query, cid.formatted);
  69. cidElm.replaceWith(hyperlinkedElm);
  70. }
  71.  
  72. function createLink(query, txt) {
  73. const a = document.createElement(`a`);
  74. a.textContent = txt;
  75. a.href = `https://www.google.co.jp/search?tbm=vid&nfpr=1&q=${encodeURIComponent(query + additionalWords)}`;
  76. a.target = `_blank`;
  77. return a;
  78. }
  79.  
  80. function checkDomain() {
  81. let result = `unknown`;
  82. if (location.host.includes(`adult.contents.fc2.com`)) {
  83. result = `FC2`;
  84. } else if (location.host.includes(`dmm.co.jp`)) {
  85. result = `FANZA`;
  86. }
  87. return result;
  88. }
  89. })();