My Function library

enter something useful

Fra 12.04.2015. Se den seneste versjonen.

Dette scriptet burde ikke installeres direkte. Det er et bibliotek for andre script å inkludere med det nye metadirektivet // @require https://update.greatest.deepsurf.us/scripts/9160/45900/My%20Function%20library.js

  1. //// ==UserScript==
  2. // @name My Function library
  3. // @namespace http://use.i.E.your.homepage/
  4. // @version 0.25
  5. // @description enter something useful
  6.  
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_deleteValue
  10.  
  11. // @run-at document-start
  12.  
  13. // @created 2015-04-06
  14. // @released 2014-00-00
  15. // @updated 2014-00-00
  16. // @history @version 0.25 - first version: public@released - 2015-04-12
  17.  
  18. // @compatible Greasemonkey, Tampermonkey
  19. // @license GNU GPL v3 (http://www.gnu.org/copyleft/gpl.html)
  20. // @copyright 2014+, Magnus Fohlström
  21. // ==/UserScript==
  22.  
  23. /*global $, jQuery*/
  24.  
  25. /*jshint -W014, -W030, -W082*/
  26. // -W014, laxbreak, Bad line breaking before '+'
  27. // -W030, Expected assignment or funtion call insted saw an expression
  28. // -W082, a function declaration inside a block statement
  29.  
  30. $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild){
  31. var found = 'found',
  32. $this = $(this.selector),
  33. $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true);
  34. if( !isChild )
  35. {
  36. (window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {})[this.selector] =
  37. window.setInterval(function () {
  38. $this.waitUntilExists(
  39. handler, shouldRunHandlerOnce, true);
  40. }, 500);
  41. }
  42. else if (shouldRunHandlerOnce && $elements.length)
  43. {
  44. window.clearInterval(window.waitUntilExists_Intervals[this.selector]);
  45. }
  46. return $this;
  47. };
  48.  
  49. $.fn.toggleClasses = function (add, remove, ifnone){
  50. var $this = $( this.selector );
  51. ifnone !== undefined && !$this.hasClass( add ) && !$this.hasClass( remove ) && $this.addClass( ifnone );
  52. $this.addClass( add ).removeClass( remove );
  53. };
  54.  
  55. //ScrollZoomTune("div.thumb .title a",1,-25,1,'slow');
  56. function ScrollZoomTune(selection, zomms, tune, ani, speed)
  57. {
  58. var body = $('body'), sel = $( selection), position;
  59. sel.size() !== 0 && (
  60. body.css('zoom',zomms),
  61. position = sel.position(),
  62. position = position.top + tune,
  63. ani == 1 ?
  64. body.animate({ scrollTop: position * zomms }, speed ) :
  65. body.scrollTop( position * zomms )
  66. )
  67. }
  68.  
  69. function inURL(search){
  70. var winLoc = window.location.href;
  71. return winLoc.search(search) !== -1;
  72. }
  73.  
  74. function checkDividedIsInteger( num, div ){
  75. return ( num % div === 0 );
  76. }
  77.  
  78. function isEven(value) {
  79. return ( value % 2 === 0 );
  80. }
  81.  
  82. String.prototype.inURL = function(){
  83. var winLoc = window.location.href;
  84. return winLoc.search(this) !== -1;
  85. };
  86.  
  87. String.prototype.inString = function(string){
  88. return string !== undefined ? string.search(this) !== -1 : false;
  89. };
  90.  
  91. String.prototype.inElem = function(search){
  92. return this !== undefined ? this.search(search) !== -1 : false;
  93. };
  94.  
  95. String.prototype.undef = function(replace){
  96. return this === undefined ? replace : this;
  97. };
  98.  
  99. String.prototype.extract = function( startChar, endChar, inside)
  100. {
  101. var str = this,
  102. startCharIndex = str.indexOf( startChar ),
  103. endCharIndex = str.indexOf( endChar );
  104.  
  105. str = str.substr( startCharIndex, endCharIndex);
  106.  
  107. if( inside == 'yes' || inside == 1 || inside === true || inside == 'inside')
  108. {
  109. str = str.replace( startChar, '').replace( endChar, '');
  110. }
  111.  
  112. return str;
  113. };
  114. /**
  115. * @return {string}
  116. */
  117. function Undefined(check,replace){
  118. return check === undefined ? replace.toString() : check.toString();
  119. }
  120. $.fn.extend({
  121. exists: function(){
  122. return this.length === 0 ? 0 : this.length;
  123. }
  124. });
  125.  
  126. function roundFloat(num,dec){
  127. var d = 1;
  128. for (var i=0; i<dec; i++){
  129. d += "0";
  130. }
  131. return Math.round(num * d) / d;
  132. }
  133.  
  134. function refreshElement( elem , speed ) //refreshElement('.videoPlayer','slow');
  135. {
  136. var data = $( elem ).html();
  137. $( elem ).empty().html( data ).fadeIn( speed );
  138. }
  139.  
  140. String.prototype.lpad = function(padString, length) {
  141. var str = this;
  142. while ( str.length < length ) {
  143. str = padString + str; }
  144. return str;
  145. };
  146.  
  147. String.prototype.formatString = function(){
  148. return this.toString()
  149. .split('!').join(' !').split('!;').join("!important;")
  150. .split(/\s+/g).join(' ')
  151. .split('{').join('{\n\t')
  152. .split('; ').join(';')
  153. .split(';').join(';\n\t')
  154. .split('*/').join('*/\n')
  155. .split(')*(').join(') * (')
  156. .split('}').join('}\n');
  157. };
  158.  
  159. //myplugin.VideoTitleA("div.thumb .title a",'on');
  160. var VideoTitleA = function( elem , state ){
  161. $( elem ).each(function()
  162. {
  163. var strTitle = $(this).attr('title'),
  164. strText = $(this).attr('data-text'),
  165. strHtml = $(this).text();
  166.  
  167. state == 'on' ? $(this).text(strTitle).attr('data-text',strHtml) : $(this).text(strText);
  168. });
  169. },
  170. /**
  171. * @return {string}
  172. */
  173. MultiString = function(f) {
  174. return f.toString().split('\n').slice(1, -1).join('\n');
  175. },
  176. c =
  177. {
  178. defaultState: 3,
  179. logState: function(){
  180. return GM_getValue('LogStateValue');
  181. },
  182. infoState: function(){
  183. return GM_getValue('InfoStateValue');
  184. },
  185. l: function( name, fn, showThis ){
  186. var State = this.logState() || this.defaultState;
  187. ( State !== 0 && State === (showThis || State) || State === 'all' ) &&
  188. window.console.log( name, fn !== undefined ? fn : '' );
  189. },
  190. i: function( name, fn, showThis ){
  191. var State = this.infoState() || this.defaultState;
  192. ( State !== 0 && State === (showThis || State) || State === 'all' ) &&
  193. window.console.info( name, fn !== undefined ? fn : '' );
  194. }
  195. },
  196. g = {
  197. winLoc : window.location.href,
  198. ms : 0,
  199. timer : function(ms){
  200. g.ms = ms;
  201. setTimeout(function(){ g.ms = 0; },ms);
  202. }
  203. };
  204.  
  205. c.i('myFunctionLibrary');