🏠 Home 

Tieba_Insert_MusicLink

贴吧自定义插入mp3链接


Install this script?
  1. // ==UserScript==
  2. // @name Tieba_Insert_MusicLink
  3. // @namespace tieba
  4. // @description 贴吧自定义插入mp3链接
  5. // @include http://tieba.baidu.com/*
  6. // @require http://libs.baidu.com/jquery/1.9.0/jquery.js
  7. // @grant GM_addStyle
  8. // @version 3.0.2
  9. // @author 初代作者为校长之怒/修复(绯色)
  10. // ==/UserScript==
  11. /***
  12. 2014年之前版本信息丢失,且本脚本真正的作者早已无更新
  13. 2014/6/1 修复火狐吧友说该脚本在chrome的浮动回帖框会出现两个插入框的问题(在此吐槽,狐吧基佬跑去使用chrome闹哪样)
  14. */
  15. //JQuery支持
  16. //音乐链接面板 GUI界面
  17. var musicUrl = '<span class="label">歌名</span><input style="width:100px" id="musicUrlTitle" placeholder="输入歌曲名" value="">';
  18. musicUrl += '&nbsp;<span class="label">链接</span><input style="width:300px" id="musicUrl" placeholder="输入链接" value="">';
  19. musicUrl += '&nbsp;<span id="convertLinks" class="btn" >插入音乐链接</span><span id="Check_status" style="color:red;display:none">歌名和链接不能为空</span>';
  20. //css
  21. var css = '.label{display:inline-block;padding:2px 4px;font-size:11.844px;font-weight:bold;line-height:14px;color:#ffffff;vertical-align:baseline;white-space:nowrap;text-shadow:0 -1px 0 rgba(0, 0, 0, 0.25);background-color:#999999;}\
  22. .btn{font-size: 12px;height: 25.6px;line-height: 25.6px;padding: 0px 2px;transition-property: #000, color;\
  23. transition-duration: 0.3s;\
  24. box-shadow: none;\
  25. background: none repeat scroll 0% 0% #00A1CB;\
  26. color: #FFF;\
  27. text-shadow: none;\
  28. border: medium none;}';
  29. GM_addStyle(css);
  30. //调用控制
  31. addNodeInsertedListener('#tb_rich_poster_container', function() {
  32. $("#tb_rich_poster").append(musicUrl);
  33. $('#convertLinks').click(check);
  34. });
  35. //函数 检查表单
  36. function check() {
  37. if (($('#musicUrlTitle').val() == '') || ($('#musicUrl').val() == '')) {
  38. $('#Check_status').css('display', 'block');
  39. setTimeout(function() {
  40. $('#Check_status').hide();
  41. }, 2000);
  42. } else {
  43. location.href = "javascript:rewriteGetContent();void(0);";
  44. convertLinks();
  45. }
  46. }
  47. //插入函数 插入音乐
  48. function convertLinks() {
  49. var url = $('#musicUrl').val();
  50. $('#musicUrl').val('');
  51. var title = $('#musicUrlTitle').val();
  52. if (url.indexOf('http://') == -1 && url.indexOf('https://') == -1 && url.indexOf('ftp://') == -1)
  53. url = 'http://' + url;
  54. var temp = '<img data-height="95" data-width="400"';
  55. temp += ' title="http://box.baidu.com/widget/flash/bdspacesong.swf?from=tiebasongwidget&amp;url=';
  56. temp += url;
  57. temp += '&amp;name=' + encodeURIComponent(title) + '&amp;artist=';
  58. temp += '&amp;extra=&amp;autoPlay=false&amp;loop=true"';
  59. temp += 'src="http://tieba.baidu.com/tb/editor/v2/music.png" class="BDE_Music">';
  60. $("#ueditor_replace").html($('#ueditor_replace').html() + temp);
  61. $('.dialogJ,.dialogJmodal').remove();
  62. }
  63. //函数 元素精确定位
  64. function addNodeInsertedListener(elCssPath, handler, executeOnce, noStyle) {
  65. var animName = "anilanim",
  66. prefixList = ["-o-", "-ms-", "-khtml-", "-moz-", "-webkit-", ""],
  67. eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  68. forEach = function(array, func) {
  69. for (var i = 0, l = array.length; i < l; i++) {
  70. func(array[i]);
  71. }
  72. };
  73. if (!noStyle) {
  74. var css = elCssPath + "{",
  75. css2 = "";
  76. forEach(prefixList, function(prefix) {
  77. css += prefix + "animation-duration:.001s;" + prefix + "animation-name:" + animName + ";";
  78. css2 += "@" + prefix + "keyframes " + animName + "{from{opacity:.9;}to{opacity:1;}}";
  79. });
  80. css += "}" + css2;
  81. GM_addStyle(css);
  82. }
  83. if (handler) {
  84. var bindedFunc = function(e) {
  85. var els = document.querySelectorAll(elCssPath),
  86. tar = e.target,
  87. match = false;
  88. if (els.length !== 0) {
  89. forEach(els, function(el) {
  90. if (tar === el) {
  91. if (executeOnce) {
  92. removeNodeInsertedListener(bindedFunc);
  93. }
  94. handler.call(tar, e);
  95. return;
  96. }
  97. });
  98. }
  99. };
  100. forEach(eventTypeList, function(eventType) {
  101. document.addEventListener(eventType, bindedFunc, false);
  102. });
  103. return bindedFunc;
  104. }
  105. }
  106. //函数 元素精确定位取消绑定
  107. function removeNodeInsertedListener(bindedFunc) {
  108. var eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"],
  109. forEach = function(array, func) {
  110. for (var i = 0, l = array.length; i < l; i++) {
  111. func(array[i]);
  112. }
  113. };
  114. forEach(eventTypeList, function(eventType) {
  115. document.removeEventListener(eventType, bindedFunc, false);
  116. });
  117. }
  118. //度娘处理函数改写(来自猫酱和小鹿姐)
  119. function rewriteGetContent() {
  120. var b = test_editor.getContent;
  121. test_editor.getContent = function() {
  122. cr_flash = [];
  123. var d = b.call(test_editor);
  124. d = d.replace(/&#39;/g, "'").replace(/&quot;/g, '"').replace(/(^(<br\/>)+)|((<br\/>)+$)/g, "");
  125. var embeds = d.match(/<embed[^>]*>/g);
  126. if (embeds) {
  127. var f = '<embed allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" scale="noborder" src="#{url}" class="BDE_Music" width="400" height="95"/>';
  128. $('#ueditor_replace .BDE_Music').each(function() {
  129. var g = $.tb.format(f, {
  130. url: $(this).attr('title')
  131. });
  132. cr_flash.push(g);
  133. });
  134. for (var i = 0; i < embeds.length; i++)
  135. d = d.replace(embeds[i], cr_flash[i]);
  136. }
  137. return d;
  138. };
  139. }
  140. location.href = "javascript:"+String(rewriteGetContent) + ";void(0)";