Greasy Fork is available in English.

UI

界面库调用接口

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/53536/281536/UI.js

  1. // ==UserScript==
  2. // @name UI
  3. // @namespace https://github.com/yeomanye
  4. // @version 0.2.1
  5. // @include *://*
  6. // @description 界面库调用接口
  7. // @author Ming Ye
  8. // ==/UserScript==
  9.  
  10. (function(context) {
  11. var TIME_SHORT = 1000;
  12. var tipsCss = {
  13. position: 'fixed',
  14. padding: '20px',
  15. transform: 'translate(-50%,-50%)',
  16. 'font-size': '18px',
  17. 'z-index': 999,
  18. background: 'black',
  19. color: 'white'
  20. };
  21. var tipsCssStyle = genderStyle(tipsCss);
  22. function genderStyle(cssObj){
  23. var cssKeys = Object.keys(cssObj),cssVals = Object.values(cssObj);
  24. var styleStr = '';
  25. for(var i=0,len=cssKeys.length;i<len;i++){
  26. var key = cssKeys[i],val = cssVals[i];
  27. styleStr += key+': '+val+';'
  28. }
  29. return styleStr
  30. }
  31. context.showTips = function(msg, time) {
  32. var width = window.innerWidth,
  33. height = window.innerHeight;
  34. time = time ? time : TIME_SHORT;
  35. var divElm = document.createElement('div');
  36. divElm.innerText = msg;
  37. divElm.setAttribute('style', tipsCssStyle);
  38. divElm.style.top = height / 2 + 'px';
  39. divElm.style.left = width / 2 + 'px';
  40. document.body.appendChild(divElm);
  41. setTimeout(function() {
  42. divElm.parentNode.removeChild(divElm);
  43. }, time);
  44. };
  45. })(window);