InstaSynchP Library

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

目前为 2014-10-19 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/5647/21913/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.6
  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 htmlDecode(value) {
  55. "use strict";
  56. return $('<div/>').html(value).text();
  57. }
  58.  
  59. function activeVideoIndex() {
  60. "use strict";
  61. return $('#playlist .active').index();
  62. }
  63.  
  64. function findUserId(id) {
  65. "use strict";
  66. var i;
  67. for (i = 0; i < window.users.length; i += 1) {
  68. if (id === window.users[i].id) {
  69. return window.users[i];
  70. }
  71. }
  72. return undefined;
  73. }
  74.  
  75. function findUserName(name) {
  76. "use strict";
  77. var i;
  78. for (i = 0; i < window.users.length; i += 1) {
  79. if (name === window.users[i].name) {
  80. return window.users[i];
  81. }
  82. }
  83. return undefined;
  84. }
  85.  
  86. function videojs() {
  87. "use strict";
  88. return $('.video-js')[0];
  89. }
  90.  
  91. function reloadPlayer() {
  92. "use strict";
  93. if (window.video) {
  94. window.video.destroy();
  95. }
  96. window.global.sendcmd('reload', null);
  97. }
  98.  
  99. function addSystemMessage(message) {
  100. "use strict";
  101. window.addMessage({
  102. username: ""
  103. }, message, 'system');
  104. }
  105.  
  106. function addErrorMessage(message) {
  107. "use strict";
  108. window.addMessage({
  109. username: ""
  110. }, message, 'errortext');
  111. }
  112.  
  113. function videoInfoEquals(a, b) {
  114. "use strict";
  115. if (!a || !b) {
  116. return false;
  117. }
  118. if (a.provider && a.provider === b.provider &&
  119. a.mediaType && a.mediaType === b.mediaType &&
  120. a.id && a.id === b.id) {
  121. return true;
  122. }
  123. return false;
  124. }

QingJ © 2025

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