InstaSynchP Library

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

目前為 2014-10-25 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/5647/22615/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.7
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Library
  9. // @license GPL-3.0
  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 htmlDecode(value) {
  67. "use strict";
  68. return $('<div/>').html(value).text();
  69. }
  70.  
  71. function activeVideoIndex() {
  72. "use strict";
  73. return $('#playlist .active').index();
  74. }
  75.  
  76. function findUserId(id) {
  77. "use strict";
  78. var i;
  79. for (i = 0; i < window.users.length; i += 1) {
  80. if (id === window.users[i].id) {
  81. return window.users[i];
  82. }
  83. }
  84. return undefined;
  85. }
  86.  
  87. function findUserUsername(name) {
  88. "use strict";
  89. var i;
  90. for (i = 0; i < window.users.length; i += 1) {
  91. if (name === window.users[i].name) {
  92. return window.users[i];
  93. }
  94. }
  95. return undefined;
  96. }
  97.  
  98. function videojs() {
  99. "use strict";
  100. return $('.video-js')[0];
  101. }
  102.  
  103. function reloadPlayer() {
  104. "use strict";
  105. if (window.video) {
  106. window.video.destroy();
  107. }
  108. window.global.sendcmd('reload', null);
  109. }
  110.  
  111. function addSystemMessage(message) {
  112. "use strict";
  113. window.addMessage({
  114. username: ""
  115. }, message, 'system');
  116. }
  117.  
  118. function addErrorMessage(message) {
  119. "use strict";
  120. window.addMessage({
  121. username: ""
  122. }, message, 'errortext');
  123. }
  124.  
  125. function videoInfoEquals(a, b) {
  126. "use strict";
  127. if (!a || !b) {
  128. return false;
  129. }
  130. if (a.provider && a.provider === b.provider &&
  131. a.mediaType && a.mediaType === b.mediaType &&
  132. a.id && a.id === b.id) {
  133. return true;
  134. }
  135. return false;
  136. }

QingJ © 2025

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