ptp_show_name1

show ptp group name

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/430418/957812/ptp_show_name1.js

  1. // ==UserScript==
  2. // @name ptp_show_name1
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description show ptp group name
  6. // @author tomorrow505
  7. // @match https://gf.qytechs.cn/zh-CN/script_versions/new
  8. // @icon https://www.google.com/s2/favicons?domain=gf.qytechs.cn
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. const boldfont = true;
  13. const coloredfont = true;
  14. const groupnamecolor = '#20B2AA';
  15.  
  16. const showblankgroups = true;
  17. const placeholder = 'Null';
  18.  
  19. const delimiter = ' / ';
  20. const blockedgroup = 'TBB';
  21. const moviesearchtitle = 'Browse Torrents ::';
  22. const douban_prex = 'https://www.bfdz.ink/tools/ptgen/?imdb=tt';
  23.  
  24. function formatText(str, color){
  25. var style = [];
  26. if(boldfont) style.push('font-weight:bold');
  27. if(coloredfont && color) style.push(`color:${groupnamecolor}`);
  28. return `<span style="${style.join(';')}">${str}</span>`;
  29. }
  30.  
  31. function setGroupName(groupname, target){
  32. var color = true;
  33. if ($(target).parent().find('.golden-popcorn-character').length) {
  34. color = false;
  35. }
  36. if ($(target).parent().find('.torrent-info__download-modifier--free').length) {
  37. color = false;
  38. }
  39. if ($(target).parent().find('.torrent-info-link--user-leeching').length) {
  40. color = false;
  41. }
  42. if ($(target).parent().find('.torrent-info-link--user-seeding').length) {
  43. color = false;
  44. }
  45. if ($(target).parent().find('.torrent-info-link--user-downloaded').length) {
  46. color = false;
  47. }
  48.  
  49. if(isEmptyOrBlockedGroup(groupname)){
  50. if($(target).text().split(delimiter).includes(blockedgroup)){
  51. $(target).html(function(i, htmlsource){
  52. return htmlsource.replace(delimiter + blockedgroup, '');
  53. });
  54. groupname = blockedgroup;
  55. }
  56. else if(showblankgroups){
  57. groupname = placeholder;
  58. }
  59. }
  60. if(!isEmpty(groupname)){
  61. var location = 1;
  62. try{ location = ptp_name_location; } catch(err) {console.log(err)}
  63. if (location == 1) {
  64. return $(target).append(delimiter).append(formatText(groupname, color));
  65. } else {
  66. return $(target).prepend(delimiter).prepend(formatText(groupname, color));
  67. }
  68. }
  69. }
  70.  
  71. function setDoubanLink(imdb_id, target){
  72. if(!isEmpty(imdb_id)){
  73. try{
  74. var td = target.parentNode.parentNode.getElementsByTagName('td')[1];
  75. var div = td.getElementsByClassName('basic-movie-list__movie__ratings-and-tags')[0];
  76. var new_div = document.createElement('div');
  77. new_div.setAttribute('class', 'basic-movie-list__movie__rating-container');
  78. new_div.style.fontweight = 'bold';
  79. var span = document.createElement('span');
  80. span.setAttribute('class', 'basic-movie-list__movie__rating__title');
  81. var a = document.createElement('a');
  82. a.href = douban_prex + imdb_id;
  83. a.text = 'PtGen';
  84. a.target = "_blank";
  85. span.appendChild(a);
  86. new_div.appendChild(span);
  87. div.insertBefore(new_div, div.firstElementChild);
  88. a.onclick = function(e){
  89. e.preventDefault();
  90. var url = 'tt' + imdb_id;
  91. var req = 'https://movie.douban.com/j/subject_suggest?q={url}'.format({ 'url': url });
  92. GM_xmlhttpRequest({
  93. method: 'GET',
  94. url: req,
  95. onload: function(res) {
  96. var response = JSON.parse(res.responseText);
  97. if (response.length > 0) {
  98. a.href = 'https://www.bfdz.ink/tools/ptgen/?imdb=' + response[0].id;
  99. } else {
  100. a.href = douban_prex + imdb_id;
  101. }
  102. window.open(a.href, target="_blank")
  103. }
  104. });
  105. }
  106. } catch(err){}
  107. }
  108. }
  109.  
  110. //Covers undefined, null, blank and whitespace-only strings
  111. function isEmpty(str){
  112. return (!str || String(str).trim().length === 0);
  113. }
  114. //I can't even...
  115. function isEmptyOrBlockedGroup(str){
  116. return (isEmpty(str) || str === blockedgroup);
  117. }
  118.  
  119. if(document.title.indexOf(moviesearchtitle) !== -1){
  120. var movies = PageData.Movies;
  121. var releases = [];
  122. var imdb_urls = [];
  123. movies.forEach(function(movie){
  124. imdb_urls[movie.GroupId] = movie.ImdbId;
  125. movie.GroupingQualities.forEach(function(torrentgroup){
  126. torrentgroup.Torrents.forEach(function(torrent){
  127. releases[torrent.TorrentId] = torrent.ReleaseGroup;
  128. });
  129. });
  130. });
  131. if(PageData.ClosedGroups != 1){
  132. releases.forEach(function(groupname, index){
  133. $(`tbody a.torrent-info-link[href$="torrentid=${index}"]`).each(function(){
  134. setGroupName(groupname, this);
  135. });
  136. });
  137. imdb_urls.forEach(function(imdbid, groupid){
  138. $(`tbody a.basic-movie-list__movie__cover-link[href$="id=${groupid}"]`).each(function(){
  139. setDoubanLink(imdbid, this);
  140. });
  141. })
  142. }
  143. else{
  144. var targetNodes = $('tbody');
  145. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  146. var myObserver = new MutationObserver(mutationHandler);
  147. var obsConfig = {childList: true, characterData: false, attributes: false, subtree: false};
  148.  
  149. targetNodes.each(function (){
  150. myObserver.observe (this, obsConfig);
  151. });
  152.  
  153. function mutationHandler (mutationRecords) {
  154. mutationRecords.forEach ( function (mutation) {
  155. if (mutation.addedNodes.length > 0) {
  156. $(mutation.addedNodes).find('a.torrent-info-link').each(function(){
  157. var mutatedtorrentid = this.href.match(/\btorrentid=(\d+)\b/)[1];
  158. var groupname = releases[mutatedtorrentid];
  159. setGroupName(groupname, this);
  160. });
  161. }
  162. });
  163. }
  164.  
  165. }
  166. }
  167. else{
  168. $('table#torrent-table a.torrent-info-link').each(function(){
  169. var groupname = $(this).parent().parent().data('releasegroup');
  170. setGroupName(groupname, this);
  171. });
  172. }
  173.  
  174. $('.torrent-info__reported').each(function(){
  175. $(this).css('color', '#FFAD86');
  176. });
  177.  
  178. $('.torrent-info__download-modifier--free').each(function(){
  179. $(this).parent().css('color', '#4DFFFF');
  180. });
  181.  
  182. $('.golden-popcorn-character').each(function(){
  183. var val=$(this).next().attr("class");
  184. if (val && !val.match(/torrent-info-link--user-leeching|torrent-info-link--user-seeding|torrent-info-link--user-downloaded/i)){
  185. $(this).parent().css('color', '#FFD700');
  186. $(this).next().css('color', '#FFD700');
  187. }else {
  188. $(this).attr('class', val)
  189. }
  190. });
  191.  
  192. $('.torrent-info__trumpable').each(function(){
  193. $(this).css('color', '#E8FFC4');
  194. });
  195.  
  196. $('.torrent-info-link--user-seeding').each(function(){
  197. $(this).css('color', 'red');
  198. });
  199.  
  200. $('.torrent-info-link--user-downloaded').each(function(){
  201. $(this).css('color', 'green');
  202. });
  203.  
  204. $('.torrent-info-link--user-leeching').each(function(){
  205. $(this).css('color', 'MediumSpringGreen');
  206. });
  207.  
  208. if (location.href.match(/id=\d+/)){
  209. $('.group_torrent_header').each(function(){
  210. var $img = $(this).find('a').eq(3).find('img');
  211. var $old_url = $img.prop('src');
  212. $img.prop('src', $old_url)
  213. })
  214. }

QingJ © 2025

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