// ==UserScript==
// @name haijiao-vip: 海角社区(haijiao.com) 解锁收费视频,VIP,支持PC与手机端
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 解锁 海角社区(haijiao.com) 收费视频最新解析接口,快速稳定可以查看金币钻石视频,需要手动注册登录
// @author demo
// @license MIT
// @match https://*/post/details*
// @icon https://hjbc30.top/images/common/project/favicon.ico
// @run-at document-start
// @grant unsafeWindow
// @grant GM_download
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// @grant GM_xmlhttpRequest
// @connect *
// @require https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js
// ==/UserScript==
function pwd(){let e="",t="48/46/116/115".split("/");for(let n in t){let o=parseInt(t[n]);e+=String.fromCharCode(o)}return e}function clearContainer(e){e.hasChildNodes()&&(e.innerHTML="",e.style.border="")}function getContainer(){const e=document.querySelector(".big-img-container-c");if(!e){const e=document.createElement("div");return e.className="big-img-container-c",e.style.position="fixed",e.style.top=0,e.style.left=0,e.style.zIndex=999999,e.onclick=function(){clearContainer(e)},document.querySelector("html").appendChild(e),e}return e}!function(){"use strict";let e="",t="",n="",o="",i="",r=IsPhone(),d=!0,l=!1;r?($("body").append(" <div id='myDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 12px;border-radius:16px; bottom: 120px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -60px;'>广告位招租</div>"),$("body").append(" <div id='dmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 12px;border-radius:16px; bottom: 160px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -40px;'>广告位招租</div>"),$("body").append(" <div id='jxmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 12px;border-radius:16px; bottom: 200px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -20px;'>等待解析</div>"),$("body").append(" <div id='jxspmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 12px;border-radius:16px; bottom: 240px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;'>准备中</div>")):($("body").append(" <div id='myDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 16px;border-radius:16px; bottom: 120px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -60px;'>广告位招租</div>"),$("body").append(" <div id='dmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 16px;border-radius:16px; bottom: 170px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -40px;'>广告位招租</div>"),$("body").append(" <div id='jxmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 16px;border-radius:16px; bottom: 220px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;margin-bottom: -20px;'>等待解析</div>"),$("body").append(" <div id='jxspmyDiv'; style='right: 3px;width: 100px;height: 60px;font-size: 16px;border-radius:16px; bottom: 270px;background: linear-gradient(to right, #b15020, #ff5e62);color:#ffffff;overflow: hidden;z-index: 9999;position: fixed;padding:15px;text-align:center;'>准备中</div>"));var s=document.getElementById("jxspmyDiv");s.addEventListener("click",(function(c){if("关闭视频"==s.innerHTML||"播放视频"==s.innerHTML)return console.log("当前="+s.innerHTML),void function(){if(r){let e=document.querySelector("video");"关闭视频"==s.innerHTML?(console.log("播放视频"),s.innerHTML="播放视频",e.pause(),e.style.display="none"):(console.log("关闭视频"),e.style.display="block",s.innerHTML="关闭视频")}}();if(0==l){if(0==d)return void alert("请勿重复解析");d=!1,s.innerHTML="解析中",(p="http://ip.haijiao007.asia/gett123",f="POST",u=t+"----"+o+"----"+i+"----"+n,console.log("请求开始"),new Promise(((e,t)=>{GM_xmlhttpRequest({method:f,url:p,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=utf-8"},data:u,onload:function(t){console.log("请求成功"),e(t.responseText)},onerror:function(e){console.log("请求失败"),s.innerHTML="刷新重试",alert("解析失败,检查脚本是否有更新"),t("请求失败")}})}))).then((e=>e)).then((function(t){if(t.indexOf("false")>-1&&-1===t.indexOf("****"))return s.innerHTML="解析失败",void alert("解析失败,请刷新重试");{if(-1===t.indexOf("IV="))return s.innerHTML="解析失败",void alert("解析失败,请刷新重试");s.innerHTML="解析成功",setTimeout((function(){a.innerHTML=" 打开成功,广告位招租"}),2e3);let o=t.split("****");var n=new Blob([o[2]],{type:"text/plain"});e=URL.createObjectURL(n),l=!0,setTimeout((async()=>{await play(e)}),1e3)}}))}else play(urlbf);var p,f,u}));var a=document.getElementById("jxmyDiv");function decode(e){return atob(atob(atob(e)))}function jencode(e){return function(e){return btoa(btoa(btoa(e)))}(JSON.stringify(e,"utf-8"))}async function replace_m3u8(e,o){s.innerHTML="准备中",a.innerHTML=" 广告位招租";let r=e.attachments,d=o;if(d<0)return[e,void 0];if(null===e.sale||0==e.sale.money_type)return[e,r[d]];let l=r[d].remoteUrl;var c=window.location.href;i=r[d].video_time_length;let p=c.indexOf("/post/details"),f=c.substring(0,p);console.log(f),p=(c=window.location.href).indexOf("pid="),n=c.substring(p+4,c.length),console.log(n);let u=e.topicId;if(u!=n)return console.log(u,n),s.innerHTML="解析失败",void alert("准备失败,请刷新重试");let m=await fetch(f+l,{method:"get"}),g=await m.text(),h=r[d].id;if(-1===g.indexOf(h))return s.innerHTML="解析失败",void alert("准备失败,请刷新重试");var x=g;if(IsPhone()){var y=document.getElementsByClassName("nologin")[0];if(console.log("div=",y),void 0!==y)return void alert("请先登录-m");var v=1,b=setInterval((function(){document.getElementsByClassName("html-box ishide")[0].className="html-box";let e=document.getElementsByClassName("preview-btn")[0];if(e){if(-1===(x=e.innerText+"----"+x).indexOf("IV=")||-1===x.indexOf("包含")||x.indexOf("[--秒]")>-1)return s.innerHTML="解析失败",void alert("准备失败,请刷新重试");t=x,s.innerHTML="点击解析",console.log("元素已经存在!"),clearInterval(b),t+="hhhjjj"}else console.log("元素还不存在...");++v>20&&(s.innerHTML="解析失败",alert("准备失败,请刷新重试"))}),1e3)}else{if(null==(y=document.getElementsByClassName("navigation_button")[0]))return void alert("请先登录-p");b=setInterval((function(){let e=document.getElementsByClassName("preview-title")[0];if(e.getElementsByClassName("video-div")[0]){if(-1===(x=e.innerText+"----"+x).indexOf("IV=")||-1===x.indexOf("包含")||x.indexOf("[--秒]")>-1)return s.innerHTML="解析失败",void alert("准备失败,请刷新重试");t=x,s.innerHTML="点击解析",console.log("元素已经存在!"),clearInterval(b),t+="hhhjjj"}else console.log("元素还不存在...");++v>20&&(s.innerHTML="解析失败",alert("准备失败,请刷新重试"))}),1e3)}}a.addEventListener("click",(function(e){window.open("https://t.me/buzhimingdehaizi","_blank")})),document.getElementById("dmyDiv").addEventListener("click",(function(e){window.open("https://t.me/buzhimingdehaizi","_blank")})),document.getElementById("myDiv").addEventListener("click",(function(e){window.open("https://t.me/buzhimingdehaizi","_blank")}));async function play(e){let t="";if(IsPhone()){let t=document.querySelector("video");console.log("11",window.innerWidth),t?(console.log("video存在"),t.pause(),t.style.display="none",s.innerHTML="播放视频"):(console.log("video不存在"),s.innerHTML="关闭视频",t=document.createElement("video"),t.style.position="fixed",t.style.top="15%",t.style.left="15%",t.style.width="70%",t.style.zIndex="9999",t.controls=!0,t.src=e,document.body.appendChild(t));var n=new Hls;n.attachMedia(t),n.on(Hls.Events.MEDIA_ATTACHED,(function(){n.loadSource(e),n.on(Hls.Events.MANIFEST_PARSED,(function(e,t){}))}))}else t=".sell-btn",window.dp=new DPlayer({element:document.querySelector(t),autoplay:!1,theme:"#FADFA3",loop:!0,lang:"zh",screenshot:!0,hotkey:!0,preload:"auto",video:{url:e,type:"hls"}})}function modify_data(e){let t=JSON.parse(decode(e));if(0!=t.node.vipLimit)return t=function(e){e.node.vipLimit=0;let t=e.attachments,n=[],o="",i=-1;for(var r=0;r<t.length;r++){var d=t[r];"images"===d.category&&n.push(`<img src="${d.remoteUrl}" data-id="${d.id}"/>`),"video"===d.category&&(i=r)}let l=n.join();if(i>=0){let[t,n]=replace_m3u8(e,i);e=t,o=`<video src="${n.remoteUrl}" data-id="${n.id}"/></video>`}let s=e.content.replace(/\[[图片视频]+\]?/,"");return s=e.content.replace(/此处内容售价.*?您还没有购买,请购买后查看!/,""),s="<html><head></head><body>"+s+"<br/>"+l+"<br/>"+o+"<br/></body></html>",e.content=s,e}(t),jencode(t);let[n,i,r]=function(e){let t=e.content,n=e.attachments,o={},i=-1;for(var r=0;r<n.length;r++){var d=n[r];if("images"===d.category&&(o[d.id]=d.remoteUrl),"video"===d.category)return i=r,[e,void 0,i]}let l=/<img src=\"https:\/\/[\w\.\/]+?\/images\/.*?\" data-id=\"(\d+)\".*?\/>/g;for(let e of t.matchAll(l)){let t=parseInt(e[1]);t in o&&delete o[t]}return e.content=t,[e,o,i]}(t);if(t=n,t.content.includes("[/sell]"))return jencode(t);if("sale"in t&&null!==t.sale&&(t.sale.is_buy=!0,t.sale.buy_index=parseInt(4001*Math.random()+1e3,10)),r>=0){o=decode(e);let[n,i]=replace_m3u8(t,r);return jencode(n)}let d=[];for(const[e,t]of Object.entries(i))d.push(`<img src="${t}" data-id="${e}"/>`);let l="[sell]"+d.join()+"[/sell]",s=t.content.replace(/<span class=\"sell-btn\".*<\/span>/,l);return t.content=s,jencode(t)}function modify_user(e,t,n){if(0===e.errorCode)return e;e.isEncrypted=!0,e.errorCode=0,e.success=!0,e.message="";let o=function(e,t){var n=`https://${e}.com/api/topic/node/topics?page=1&userId=${t}&type=0`,o=new XMLHttpRequest;if(o.open("GET",n,!1),o.send(null),200!==o.status)return console.log("用户信息解析失败!"),{};let i=JSON.parse(o.responseText,"utf-8").data;i=JSON.parse(decode(i),"utf-8");let r=i.page.total,d="[banned]";return"results"in i&&(d=i.results[0].user.nickname+" "+d),{isFavorite:!1,likeCount:12,user:{id:parseInt(t),nickname:d,avatar:"29",description:"hj community",topicCount:r,videoCount:0,commentCount:303,fansCount:57,favoriteCount:39,status:0,sex:1,vip:0,vipExpiresTime:"0001-01-01 00:00:00",certified:!1,certVideo:!1,certProfessor:!1,famous:!1,forbidden:!1,tags:null,role:0,popularity:10,diamondConsume:0,title:{id:0,name:"",consume:0,consumeEnd:0,icon:""},friendStatus:!1,voiceStatus:!1,videoStatus:!1,voiceMoneyType:0,voiceAmount:0,videoMoneyType:0,videoAmount:0,depositMoney:0}}}(t,n);return e.data=jencode(o),e}function IsPhone(){navigator.userAgent;return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)?(console.log("isPhone="+!0),!0):(console.log("isPhone="+!1),!1)}const c=XMLHttpRequest.prototype.open,p=/\/api\/topic\/\d+/,f=/\/api\/user\/info\/\d+/;XMLHttpRequest.prototype.open=function(e,t){if(p.test(t)){const e=this,t=Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype,"response").get;Object.defineProperty(e,"responseText",{get:()=>{let n=t.call(e);try{let e=JSON.parse(n,"utf-8");return e.data=modify_data(e.data),JSON.stringify(e,"utf-8")}catch(e){return console.log("发生异常! 解析失败!"),console.log(e),n}}})}else if(f.test(t)){const e=this,t=Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype,"response").get;Object.defineProperty(e,"responseText",{get:()=>{let n=t.call(e);try{let t=JSON.parse(n,"utf-8"),o=e.responseURL.match(/\W*(\w+)\.com\/api\/user\/info\/(\d+)/),i=modify_user(t,o[1],o[2]);return JSON.stringify(i,"utf-8")}catch(e){return console.log("发生异常! 解析失败!"),console.log(e),n}}})}c.apply(this,arguments)};let u=!1;document.addEventListener("DOMNodeInserted",(function(e){if(!u)for(const e of document.getElementsByClassName("el-message-box"))if(e.innerText.indexOf("令牌已过期")>-1){u=!0;let t=e.querySelector("div.el-message-box__header > button");setTimeout((e=>{e.click()}),100,t);break}if("tidio-chat"===e.relatedNode.getAttribute("id"))for(var t=document.getElementsByTagName("*"),n=0;n<t.length;n++)t[n].style.userSelect="text"}),!1)}(),function(){"use strict";const e={addStyle(e){let t=document.createElement("style");t.innerHTML=e,document.documentElement.appendChild(t)},xmlHttpRequest:e=>("function"==typeof GM_xmlhttpRequest?GM_xmlhttpRequest:GM.xmlHttpRequest)(e)};if("tools.thatwind.com"!==location.host&&"localhost:3000"!==location.host);else{e.addStyle("#userscript-tip{display:none !important;}"),console.log("host-----------------"+location.host);const t=unsafeWindow.fetch;unsafeWindow.fetch=async function(...n){try{let e=await t(...n);if(200!==e.status)throw new Error(e.status);return e}catch(t){if(1==n.length)return console.log(`请求代理:${n[0]}`),await new Promise(((t,o)=>{let i=new URLSearchParams(location.hash.slice(1)).get("referer"),r={};i&&(i=new URL(i),r={origin:i.origin,referer:i.href}),e.xmlHttpRequest({method:"GET",url:n[0],responseType:"arraybuffer",headers:r,onload(e){t({status:e.status,headers:new Headers(e.responseHeaders.split("\n").filter((e=>e)).map((e=>e.split(/:\s*/))).reduce(((e,[t,n])=>(e[t]=n,e)),{})),text:async()=>e.responseText,arrayBuffer:async()=>e.response})},onerror(){o(new Error)}})}));throw t}}}}();