InstaSynchP Library

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

当前为 2014-10-18 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/5647/21773/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.5
  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. // see below for better implementation!
  41. String.prototype.startsWith = function (str) {
  42. return this.indexOf(str) === 0;
  43. };
  44. }
  45.  
  46. function isBlackname(username) {
  47. "use strict";
  48. if (typeof username !== 'string') {
  49. return false;
  50. }
  51. return username.match(/^([A-Za-z0-9]|([\-_](?![\-_]))){5,16}$/) !== null;
  52. }
  53.  
  54. function activeVideoIndex() {
  55. "use strict";
  56. return $('#playlist .active').index();
  57. }
  58.  
  59. function findUserId(id) {
  60. "use strict";
  61. var i;
  62. for (i = 0; i < window.users.length; i += 1) {
  63. if (id === window.users[i].id) {
  64. return window.users[i];
  65. }
  66. }
  67. return undefined;
  68. }
  69.  
  70. function findUserName(name) {
  71. "use strict";
  72. var i;
  73. for (i = 0; i < window.users.length; i += 1) {
  74. if (name === window.users[i].name) {
  75. return window.users[i];
  76. }
  77. }
  78. return undefined;
  79. }
  80.  
  81. function videojs() {
  82. "use strict";
  83. return $('.video-js')[0];
  84. }
  85.  
  86. function reloadPlayer() {
  87. "use strict";
  88. if (window.video) {
  89. window.video.destroy();
  90. }
  91. window.global.sendcmd('reload', null);
  92. }
  93.  
  94. function addSystemMessage(message) {
  95. "use strict";
  96. window.addMessage({
  97. username: ""
  98. }, message, 'system');
  99. }
  100.  
  101. function addErrorMessage(message) {
  102. "use strict";
  103. window.addMessage({
  104. username: ""
  105. }, message, 'errortext');
  106. }
  107.  
  108. function videoInfoEquals(a, b) {
  109. "use strict";
  110. if (!a || !b) {
  111. return false;
  112. }
  113. if (a.provider && a.provider === b.provider &&
  114. a.mediaType && a.mediaType === b.mediaType &&
  115. a.id && a.id === b.id) {
  116. return true;
  117. }
  118. return false;
  119. }

QingJ © 2025

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