GoTo115

选择115礼包码后直接打开接收界面

  1. // ==UserScript==
  2. // @name GoTo115
  3. // @namespace http://bbs.fuli.ba/?fromuser=benbenben
  4. // @version 0.2
  5. // @description 选择115礼包码后直接打开接收界面
  6. // @author benbenben
  7. // @match http://*/*
  8. // @match https://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. var $imgLink = "http://ww3.sinaimg.cn/mw690/61ceb008jw1ereg3uqk73j206e06eq2s.jpg";
  13. var $goTo115LB = function(eleGotoUI, eleContainer) {
  14. var re = /5lb[a-z0-9]{5,9}/ig;
  15. var eleTitle = document.getElementsByTagName("title")[0];
  16. eleContainer = eleContainer || document;
  17. var funGetSelectTxt = function() {
  18. var txt = "";
  19. if(document.selection) {
  20. txt = document.selection.createRange().text; // IE
  21. } else {
  22. txt = document.getSelection();
  23. }
  24. return txt.toString();
  25. };
  26. eleContainer.onmouseup = function(e) {
  27. e = e || window.event;
  28. var txt = funGetSelectTxt(), sh = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  29. var left = (e.clientX - 40 < 0) ? e.clientX + 20 : e.clientX - 40, top = (e.clientY - 40 < 0) ? e.clientY + sh + 20 : e.clientY + sh - 40;
  30. if (re.test(txt)) {
  31. eleGotoUI.style.display = "inline";
  32. eleGotoUI.style.left = left + "px";
  33. eleGotoUI.style.top = top + "px";
  34. } else {
  35. eleGotoUI.style.display = "none";
  36. }
  37. };
  38. eleGotoUI.onclick = function() {
  39. var txt = funGetSelectTxt();
  40. if (txt) {
  41. var lbs = txt.match(re);
  42. if (lbs) {
  43. for (var x in lbs) {
  44. window.open('http://115.com/lb/' + lbs[x]);
  45. }
  46. }
  47. }
  48. };
  49. };
  50.  
  51. function addGlobalStyle(css) {
  52. var head, style;
  53. head = document.getElementsByTagName('head')[0];
  54. if (!head) { return; }
  55. style = document.createElement('style');
  56. style.type = 'text/css';
  57. style.innerHTML = css;
  58. head.appendChild(style);
  59. }
  60.  
  61. function init() {
  62. addGlobalStyle('.img_115_logo{display:none; position:absolute; cursor:pointer; z-index: 100;}');
  63. var logo = document.createElement("p");
  64. logo.innerHTML = '<img width="26px" height="26px" id="img115Logo" class="img_115_logo" title="打开礼包文件" src="' + $imgLink + '" />';
  65. document.body.insertBefore(logo, document.body.firstChild);
  66. }
  67.  
  68. init();
  69. $goTo115LB(document.getElementById("img115Logo"));