GOG Language BBCode quick copy

Allows you to copy the gog languages in a BBCode fashion

  1. // ==UserScript==
  2. // @name GOG Language BBCode quick copy
  3. // @namespace https://gf.qytechs.cn/
  4. // @version 0.02
  5. // @description Allows you to copy the gog languages in a BBCode fashion
  6. // @author byJ
  7. // @license MIT
  8. // @match https://www.gog.com/en/game/*
  9. // @grant GM_xmlhttpRequest
  10. // @grant GM_setClipboard
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // ==/UserScript==
  14.  
  15.  
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. if(window.location.hostname === 'www.gog.com'){
  21. gogButton();
  22. }
  23.  
  24. function gogButton(){
  25. const $btn = document.createElement('a');
  26. const text = 'Copy BBCode';
  27. $btn.classList.add('btnv6_blue_hoverfade', 'btn_small');
  28. const $text = $btn.appendChild(document.createElement('span'));
  29. $text.innerHTML = `${text}<img src="https://ptpimg.me/sx226x.png">`;
  30. $btn.addEventListener('click', function(){
  31. GM_setClipboard(parseGOGLanguage(document), 'text');
  32. $text.childNodes[0].nodeValue = 'copied';
  33. setTimeout(function(){$text.childNodes[0].nodeValue = text; }, 3000);
  34. });
  35.  
  36. const $container = document.querySelector('div.details.table.table--without-border.ng-scope')
  37. const $before = document.querySelectorAll('.details__separator')[1]
  38. $container.insertBefore($btn, $before);
  39. }
  40.  
  41. function parseGOGLanguage($document){
  42.  
  43. let languages_div_list = $document.querySelectorAll('div.details__content.table__row-content.details__languages-row');
  44.  
  45. if(!languages_div_list) return;
  46.  
  47. let languages = {
  48. 'Audio': [],
  49. 'Text': [],
  50. };
  51. languages_div_list.forEach(function (element) {
  52. let language = element.querySelector('div').textContent.trim();
  53. let audio = element.querySelectorAll('use')[0].getAttribute('xlink:href');
  54. let text = element.querySelectorAll('use')[1].getAttribute('xlink:href');
  55. if (audio === '#check_tick'){ languages['Audio'].push(language) }
  56. if (text === '#check_tick'){ languages['Text'].push(language) }
  57. })
  58.  
  59. let output = ''
  60. let keys = Object.keys(languages);
  61.  
  62. for(var i = 0; i < keys.length; i++){
  63. let key = keys[i];
  64. if (languages[key].length === 0){
  65. continue
  66. }
  67.  
  68. let keygroup = [key];
  69.  
  70. if(i < keys.length - 1){
  71. for(var iNext = i+1; iNext < keys.length; iNext){
  72. if(areSame(languages[keys[i]], languages[keys[iNext]])) {
  73. keygroup.push(keys[iNext]);
  74. keys.splice(iNext,1);
  75. } else {
  76. iNext++;
  77. }
  78. }
  79. }
  80.  
  81. const multi = languages[key].length > 1;
  82. if(keys.length === 1){
  83. output += `[b]Language${multi ? "s": ""}[/b]: `;
  84. }else {
  85. output += `[b]${keygroup.join(' and ')} Language${multi ? "s": ""}[/b]: `;
  86. }
  87.  
  88. if(multi){
  89. let lastItem = languages[key].pop();
  90. output += languages[key].join(', ');
  91. output += ` and ${lastItem}`;
  92. } else {
  93. output += languages[key];
  94. }
  95. output += '\n';
  96. }
  97. return output;
  98. }
  99.  
  100. function areSame(array1, array2){
  101. return array1.length === array2.length && array1.sort().every((value, index) => value === array2.sort()[index])
  102. }
  103. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址