Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. (function(){
  2. var hasFrame = window.parent!=window,
  3. scripts = document.getElementsByTagName('script'),
  4. current = scripts[scripts.length-1],
  5. config = current.getAttribute('data-config'),
  6. head = document.getElementsByTagName("head")[0],
  7. dest = location.href.replace(/rhinplayer\=true/g, 'rhinplayer=false'),
  8. destHost = dest.substr(0,dest.indexOf('/',10)),
  9. rhin = current.getAttribute('src').replace(/script\.js.*/g,'rhin.html')+'#'+dest,
  10. rhinHost = rhin.substr(0,rhin.indexOf('/',10)),
  11. isOutside = !hasFrame || location.href.indexOf("rhinplayer=true")>0,
  12. postMessage = function(msg){
  13. return window.top.document.getElementById('rhinframe')
  14. .contentWindow.postMessage(msg,rhinHost);
  15. },
  16. postFactory = function(obj,keys){
  17. var keys = keys.split(','),
  18. post = function(key){
  19. return function(arg){
  20. var argStr = '';
  21. if(typeof(arg)!='undefined')
  22. argStr = (key.match(/(play|queue)/) ? 'new Song(':'(') +
  23. JSON.stringify(arg)+')';
  24. postMessage('rhin.'+key+'('+argStr+')');
  25. }
  26. };
  27. for(var i=0;i<keys.length;i++){
  28. var key = keys[i];
  29. obj[key] = post(key);
  30. }
  31. },
  32. postConfig = function(config){
  33. if(!isOutside)
  34. postMessage('rhin.config('+config+')');
  35. },
  36.  
  37. addEvent = function(elm, evType, fn) {
  38. if(elm.addEventListener)
  39. elm.addEventListener(evType, fn);
  40. else if (elm.attachEvent)
  41. elm.attachEvent('on' + evType, fn);
  42. else
  43. elm['on' + evType] = fn;
  44. },
  45. isIE = (function(){
  46. var undef,v = 3,div = document.createElement('div'),
  47. all = div.getElementsByTagName('i');
  48. while (div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',all[0] );
  49. return v > 4 ? v : undef;
  50. })(),
  51. isMobile = navigator.userAgent.match(/iPad|iPhone|Android|Blackberry/i),
  52. isIPad= navigator.userAgent.match(/iPad/i),
  53.  
  54. init = function(){
  55. if(!document.body){
  56. setTimeout(init,10);
  57. return;
  58. }
  59. if(isOutside) outside(); else inside();
  60. },
  61.  
  62. outside = function(){
  63. var css = 'html,body{overflow:hidden;} body{margin:0;padding:0;border:0;} img,a,embed,object,div,address,table,iframe,p,span,form,header,section,footer{ display:none;border:0;margin:0;padding:0; } #tumblr_controls{display:none;} #rhinframe{display:block; background-color:transparent; position:fixed; top:0px; left:0px; width:100%; height:100%; z-index:1667;} ';
  64. var style = document.createElement('style');
  65. style.type = 'text/css';
  66. style.id = 'rhincss';
  67.  
  68. if(style.styleSheet) style.styleSheet.cssText = css;
  69. else style.appendChild(document.createTextNode(css));
  70.  
  71. head.appendChild(style);
  72. /*
  73. while(head.firstChild.id!="rhincss")
  74. head.removeChild(head.firstChild);
  75. */
  76.  
  77. var rhinframe = document.createElement('iframe');
  78. rhinframe.frameBorder = 0;
  79. rhinframe.id = "rhinframe";
  80. rhinframe.allowTransparency = true;
  81. rhinframe.src = rhin;
  82.  
  83. document.body.insertBefore(rhinframe,document.body.firstChild);
  84.  
  85. var resize = function(){
  86. rhinframe.style.height = (function(){
  87. if( typeof( window.innerHeight ) == 'number' )
  88. return window.innerHeight;
  89. else if( document.documentElement && document.documentElement.clientHeight )
  90. return document.documentElement.clientHeight;
  91. else if( document.body && document.body.clientHeight )
  92. return document.body.clientHeight;
  93. })();
  94. };
  95.  
  96. addEvent(window,'load',function() {
  97. setTimeout(function(){
  98. while(document.body.firstChild!=rhinframe)
  99. document.body.removeChild(document.body.firstChild);
  100. while(document.body.lastChild!=rhinframe)
  101. document.body.removeChild(document.body.lastChild);
  102. resize();
  103. },0);
  104. });
  105.  
  106. //fix frame height in IE
  107. addEvent(window,'resize',resize);
  108. //pushState and hash change detection
  109. var getPath = function(){
  110. return location.href.replace(/#.*/,'');
  111. },
  112. path = getPath(),
  113. hash = location.hash;
  114. setInterval(function(){
  115. if(getPath()!=path){
  116. path = getPath();
  117. window.rhininside.location.replace(path);
  118. }
  119. if(location.hash != hash){
  120. hash = location.hash;
  121. window.rhininside.location.hash = hash;
  122. }
  123. },100);
  124. },
  125. inside = function(){
  126. //change title
  127. window.top.document.title = document.title;
  128. //fix links
  129. var filter = function(host){
  130. host = host.replace(/blogspot.[a-z.]*/i,'blogspot.com');
  131. host = host.replace(/^(http(s)?:\/\/)?(www.)?/i,'');
  132. return host;
  133. };
  134. addEvent(document.body,'click',function(e){
  135. var tar = e.target;
  136. while(!tar.tagName.match(/^(a|area)$/i) && tar!=document.body)
  137. tar = tar.parentNode;
  138. if(tar.tagName.match(/^(a|area)$/i) &&
  139. !tar.href.match(/.(jpg|png)$/i) && //ignore picture link
  140. !tar.href.match(/^javascript:/) //ignore javascript link
  141. ){
  142. if(tar.href.indexOf('#')==0){
  143. //hash
  144. if(tar.href != "#"){
  145. window.top.rhininside = window;
  146. window.top.location.hash = location.hash;
  147. e.preventDefault();
  148. }
  149. }else if(tar.title.match(/^(rhin:|\[rhin\])/i)){
  150. //rhin Play link
  151. var title = tar.title.replace(/^(rhin:|\[rhin\])( )?/i,'');
  152. var url = tar.href;
  153. rhin.play({title:title,url:url});
  154. e.preventDefault();
  155. }else if(tar.href.match(/\.css$/)){
  156. //auto add skin
  157. window.open('http://rhinplayer.co/#skin='+tar.href,'_blank');
  158. window.focus();
  159. e.preventDefault();
  160. }else if(filter(tar.href).indexOf(filter(location.host))==-1 ){
  161. if(tar.href.match(/^http(s)?/)){
  162. //external links
  163. window.open(tar.href,'_blank');
  164. window.focus();
  165. e.preventDefault();
  166. }
  167. }else if(history.pushState){
  168. //internal link & has pushState
  169. //change address bar href
  170. var url = filter(tar.href).replace(filter(destHost),'');
  171. window.top.rhininside = window;
  172. window.top.history.pushState(null,null,url);
  173. e.preventDefault();
  174. }
  175. }
  176. });
  177.  
  178. };
  179.  
  180. //rhin interface
  181. var rhin = {};
  182.  
  183. postFactory(rhin,
  184. 'queue,play,pause,next,previous,volume,skin,placement,'+
  185. 'loadPlaylist,repeatMode,isShuffle,showPlaylist,'+
  186. 'togglePlaylist,toggleShuffle,changeRepeatMode');
  187.  
  188. if(window.rhin && window.rhinMusicPlayer) return;
  189.  
  190. if (!isMobile) {
  191. init();
  192. }
  193.  
  194. //send config
  195. if(config) postConfig(config);
  196. rhin.init = postConfig;
  197.  
  198. window.rhinMusicPlayer = window.rhinMusicPlayer || rhin;
  199. window.rhin = window.rhin || rhin;
  200. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement