InstaSynchP Library

Basic function that are needed by several scripts use with @require

当前为 2014-11-28 提交的版本,查看 最新版本

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

  1. // ==UserScript==
  2. // @name InstaSynchP Library
  3. // @namespace InstaSynchP
  4. // @description Basic function that are needed by several scripts use with @require
  5.  
  6. // @version 1.0.8
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Library
  9. // @license MIT
  10.  
  11. // @include http://*.instasynch.com/*
  12. // @include http://instasynch.com/*
  13. // @include http://*.instasync.com/*
  14. // @include http://instasync.com/*
  15. // @grant none
  16. // @run-at document-start
  17. // ==/UserScript==
  18.  
  19. //http://joquery.com/2012/string-format-for-javascript
  20. if (typeof String.prototype.format !== 'function') {
  21. String.prototype.format = function () {
  22. // The string containing the format items (e.g. "{0}")
  23. // will and always has to be the first argument.
  24. var theString = this,
  25. i,
  26. regEx;
  27.  
  28. // start with the second argument (i = 1)
  29. for (i = 0; i < arguments.length; i += 1) {
  30. // "gm" = RegEx options for Global search (more than one instance)
  31. // and for Multiline search
  32. regEx = new RegExp("\\{" + (i) + "\\}", "gm");
  33. theString = theString.replace(regEx, arguments[i]);
  34. }
  35. return theString;
  36. };
  37. }
  38. //http://stackoverflow.com/a/646643
  39. if (typeof String.prototype.startsWith !== 'function') {
  40. String.prototype.startsWith = function (str) {
  41. return this.slice(0, str.length) == str;
  42. };
  43. }
  44. if (typeof String.prototype.endsWith != 'function') {
  45. String.prototype.endsWith = function (str){
  46. return this.slice(-str.length) == str;
  47. };
  48. }
  49.  
  50. //http://stackoverflow.com/a/1978419
  51. if (typeof String.prototype.contains !== 'function') {
  52. String.prototype.contains = function (it) {
  53. return this.indexOf(it) !== -1;
  54. };
  55. }
  56.  
  57.  
  58. function isBlackname(username) {
  59. "use strict";
  60. if (typeof username !== 'string') {
  61. return false;
  62. }
  63. return username.match(/^(?:[A-Za-z0-9]|(?:[\-_](?![\-_]))){5,16}$/) !== null;
  64. }
  65.  
  66. function isGreyname(username) {
  67. "use strict";
  68. if (typeof username !== 'string') {
  69. return false;
  70. }
  71. return username.match(/^(?:[A-Za-z0-9]|(?:[\-_](?![\-_]))){1,16}$/) !== null;
  72. }
  73.  
  74. function htmlDecode(value) {
  75. "use strict";
  76. return $('<div/>').html(value).text();
  77. }
  78.  
  79. function activeVideoIndex() {
  80. "use strict";
  81. return $('#playlist .active').index();
  82. }
  83.  
  84. function findUserId(id) {
  85. "use strict";
  86. var i;
  87. for (i = 0; i < window.users.length; i += 1) {
  88. if (id === window.users[i].id) {
  89. return window.users[i];
  90. }
  91. }
  92. return undefined;
  93. }
  94.  
  95. function findUserUsername(name) {
  96. "use strict";
  97. var i;
  98. for (i = 0; i < window.users.length; i += 1) {
  99. if (name === window.users[i].name) {
  100. return window.users[i];
  101. }
  102. }
  103. return undefined;
  104. }
  105.  
  106. function videojs() {
  107. "use strict";
  108. return $('.video-js')[0];
  109. }
  110.  
  111. function reloadPlayer() {
  112. "use strict";
  113. if (window.video) {
  114. window.video.destroy();
  115. }
  116. window.global.sendcmd('reload', null);
  117. }
  118.  
  119. function addSystemMessage(message) {
  120. "use strict";
  121. window.addMessage({
  122. username: ""
  123. }, message, 'system');
  124. }
  125.  
  126. function addErrorMessage(message) {
  127. "use strict";
  128. window.addMessage({
  129. username: ""
  130. }, message, 'errortext');
  131. }
  132.  
  133. function videoInfoEquals(a, b) {
  134. "use strict";
  135. if (!a || !b) {
  136. return false;
  137. }
  138. if (a.provider && a.provider === b.provider &&
  139. a.mediaType && a.mediaType === b.mediaType &&
  140. a.id && a.id === b.id) {
  141. return true;
  142. }
  143. return false;
  144. }

QingJ © 2025

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