WXtrialInterface.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="x5-orientation" content="portrait" />
  8. <meta name="screen-orientation" content="portrait" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <!-- 删除苹果默认的工具栏和菜单栏 -->
  12. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  13. <!-- 设置苹果工具栏颜? -->
  14. <meta name="format-detection" content="telphone=no, email=no">
  15. <!-- 忽略页面中的数字识别为电话,忽略email识别 -->
  16. <!-- 启用360浏览器的极速模?(webkit) -->
  17. <meta name="renderer" content="webkit">
  18. <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑? -->
  19. <meta name="HandheldFriendly" content="true">
  20. <!-- 微软的老式浏览? -->
  21. <meta name="MobileOptimized" content="320">
  22. <!-- 不能旋转,问题出在这 -->
  23. <!-- UC强制全屏 -->
  24. <meta name="full-screen" content="yes">
  25. <!-- QQ强制全屏 -->
  26. <meta name="x5-fullscreen" content="true">
  27. <!-- UC应用模式 -->
  28. <meta name="browsermode" content="application">
  29. <!-- QQ应用模式 -->
  30. <meta name="x5-page-mode" content="app">
  31. <!-- windows phone 点击无高? -->
  32. <meta name="msapplication-tap-highlight" content="no">
  33. <link rel="stylesheet" type="text/css" href="css/WXtrialInterface.css" />
  34. <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css" />
  35. <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css" />
  36. </head>
  37. <body class="scroll h-player" style="overscroll-behavior: contain;">
  38. <div class="container" id="player">
  39. <div class="muted" id="btnMuted">
  40. <div class="control-right-img" data-id="1">
  41. <img src="../static/img/xuanfu_icon.png">
  42. </div>
  43. </div>
  44. <div id="wine">
  45. <video id="playerVideo" muted="muted" x5-video-orientation="landscape" playsinline="true" autoplay="true"
  46. webkit-playsinline="true" x5-playsinline="true" x5-video-player-type="h5" x5-video-player-fullscreen="false"
  47. style="pointer-events: none;object-fit: fill;width: 100%;height:100%"></video>
  48. <div id="box"></div>
  49. <audio preload="auto" autoplay controls poster="images/loader-thumb.jpg" id="audioPlayer"
  50. style="position: absolute;top: 0;width: 0;height: 0;"></audio>
  51. </div>
  52. <div class="leftmains">
  53. <div class="PictureQualityMain">
  54. <div class="PictureQuality " data-id="1803000">高清</div>
  55. <div class="PictureQuality avit" data-id="1243000">标清</div>
  56. <div class="PictureQuality" data-id="400000">极速</div>
  57. <div class="PictureQuality" data-id="200">自动</div>
  58. </div>
  59. <div class="operation">
  60. <div class="upload" id="showsuss" data-text="uploads">
  61. <img src="../static/img/wx/shangchuan_icon.png">
  62. <div>上传</div>
  63. </div>
  64. <div class="upload" onclick="showShearPlate()" data-text="Shearplate">
  65. <img src="../static/img/wx/jianqieban_icon.png">
  66. <div>剪贴板</div>
  67. </div>
  68. <div class="upload" id="upload" data-text="Signout">
  69. <img src="../static/img/wx/tuichu_icon.png">
  70. <div>退出</div>
  71. </div>
  72. </div>
  73. </div>
  74. <div class="bottommains">
  75. <div class="botmat1">
  76. <div class="botmat1img" data-text="gengduo">
  77. <img src="../static/img/wx/gengduo_icon.png">
  78. </div>
  79. </div>
  80. <div class="botmat1">
  81. <div class="botmat1img" data-text="home">
  82. <img src="../static/img/wx/home_icon.png">
  83. </div>
  84. </div>
  85. <div class="botmat1">
  86. <div class="botmat1img" data-text="return">
  87. <img src="../static/img/wx/fanhui_icon.png">
  88. </div>
  89. </div>
  90. </div>
  91. <img class="loading loading_sceen_pic" />
  92. </div>
  93. <div class="mask">
  94. <div class="box-shear-plate"></div>
  95. <img class="close" onclick="handleClose()" src="img/guanbi_icon@2x.png" alt="">
  96. </div>
  97. <div class="weui-mask_transparent"></div>
  98. <div class="weui-toast weui_loading_toast weui-toast--visible">
  99. <div class="weui_loading"><i class="weui-loading weui-icon_toast"></i></div>
  100. <p class="weui-toast_content">数据加载中</p>
  101. </div>
  102. <body oncontextmenu="Back()">
  103. </body>
  104. <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
  105. <script src="https://lf1-cdn-tos.bytegoofy.com/goofy/developer/jssdk/jssdk-1.0.3.js"></script>
  106. <script type="text/javascript" src="../static/js/jquery-1.11.0.min.js"></script>
  107. <script type="text/javascript" src="helper.js"></script>
  108. <script type="text/javascript" src="pcm-player.js"></script>
  109. <script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
  110. <script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
  111. <script type="text/javascript" src="WXdraw.js?v=110"></script>
  112. <script type="text/javascript" src="jmuxer.js"></script>
  113. <script>
  114. var isAudioPlay = false;
  115. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  116. var video = document.getElementById("playerVideo");
  117. video.play();
  118. setTimeout(() => { // 抖音环境需要设置延时,不然会有video默认图显示
  119. $.alert({
  120. title: '提示',
  121. text: '开始使用云手机',
  122. onOK: function () {
  123. setTimeout(() => {
  124. isAudioPlay = true;
  125. }, 1000);
  126. }
  127. });
  128. }, 1000)
  129. }else{
  130. $.alert({
  131. title: '提示',
  132. text: '开始使用云手机',
  133. onOK: function () {
  134. var video = document.getElementById("playerVideo");
  135. video.play();
  136. isAudioPlay = true;
  137. }
  138. });
  139. }
  140. var topwinHeight = window.screen.height - window.innerHeight + 30; //计算title top 头部
  141. $('#wine').css({
  142. "width": window.screen.width,
  143. "height": window.screen.height - topwinHeight - 20,
  144. "position": "absolute"
  145. });
  146. $('.loading').css({
  147. "width": window.screen.width,
  148. "height": window.screen.height - topwinHeight - 20
  149. });
  150. var winese = document.createElement("wine");
  151. wine.style.top = "-" + winese + 'px';
  152. var requestCount = 0;
  153. var isVisuable = true;
  154. var isFeed = true;
  155. var isDrag = false;
  156. var isEnough = true;
  157. var isFinish = false;
  158. var delayTime = new Date().getTime();
  159. var curTime = new Date().getTime();
  160. var myVideo = document.getElementById("playerVideo");
  161. Module = {};
  162. Module.onRuntimeInitialized = function () {
  163. isFinish = true;
  164. }
  165. var isWSS = true;
  166. var parameters = GetRequest();
  167. var ip = parameters["ip"];
  168. var cardToken = parameters["cardToken"];
  169. cardToken = cardToken && cardToken.replace(/@/g, "=");
  170. var appletPushAddress = parameters["appletPushAddress"];
  171. var socketURL = isWSS ? "wss://" + appletPushAddress + "?cardIp=" + ip + "&token=" + cardToken : "ws://" + appletPushAddress + "?cardIp=" + ip + "&token=" + cardToken;
  172. // var socketURL = "wss://192.168.31.198/businessChannel?cardIp=192.168.20.53&token=LDAz32tutqS9wQqi0WlmvJ68/Is83cX+kavJQij1IMRvewgZ1dLvviFZqd4b8gcaR1eLztR/ViRLyyAVvZO7GA==";
  173. // var socketURL = "ws://192.168.20.53:9100";
  174. var jmuxer = new JMuxer({
  175. node: 'playerVideo',
  176. flushingTime: 33,
  177. fps: 30,
  178. mode: 'video',
  179. debug: false
  180. });
  181. window.onload = function () {
  182. curTime = new Date().getTime();
  183. var myPlay = document.getElementById("wine");
  184. myPlay.onkeydown = function (event) {
  185. ExexuteKeyDown(e.keyCode);
  186. }
  187. }
  188. var ws, errorTime = 0;
  189. doConnect();
  190. // 节流
  191. // 设置一个标志
  192. function throttle(fn, delay) {
  193. let flag = true;
  194. errorTime += delay;
  195. return () => {
  196. if (!flag) return;
  197. flag = false;
  198. timer = setTimeout(() => {
  199. fn();
  200. flag = true;
  201. }, delay);
  202. };
  203. }
  204. var intervaler;
  205. function doConnect() {
  206. ws = new WebSocket(socketURL);
  207. ws.binaryType = 'arraybuffer';
  208. intervaler = setInterval(() => {
  209. if (ws.readyState === 1) {
  210. ws.send("ping");
  211. } else {
  212. clearInterval(intervaler);
  213. $.toast("画面异常,请重新进入", "text");
  214. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  215. tt.miniProgram.switchTab({
  216. url: '/pages/home/home'
  217. })
  218. }else{
  219. wx.miniProgram.switchTab({
  220. url: '/pages/home/home'
  221. })
  222. }
  223. }
  224. }, 3000);
  225. ws.addEventListener('open', function (event) {
  226. // sn只要长度满足17位随机数,不需要从后台获取
  227. var verifyBuffer = VerifyCode('RK3923C1201900139', cardToken);
  228. console.log("鉴权报文:" + PrintArry(verifyBuffer));
  229. ws.send(verifyBuffer);
  230. });
  231. ws.addEventListener('error', function (event) {
  232. ws.close();
  233. clearInterval(intervaler);
  234. throttle(doConnect, 100);
  235. if (errorTime > 1000) {
  236. $.toast("画面异常,请重新进入", "text");
  237. wsss.close();
  238. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  239. tt.miniProgram.switchTab({
  240. url: '/pages/home/home'
  241. })
  242. }else{
  243. wx.miniProgram.switchTab({
  244. url: '/pages/home/home'
  245. })
  246. }
  247. }
  248. });
  249. ws.addEventListener('message', function (event) {
  250. var data = ParseProto(event.data); //JAVA服务器转发
  251. if (isAudioPlay) {
  252. $('.weui-mask_transparent').hide();
  253. $('.weui-toast').hide();
  254. $('.loading').hide();
  255. }
  256. var input = new Uint8Array(event.data);
  257. if (data.audio != null && isAudioPlay) { //喂音频
  258. if (input[0] == 0xff) {
  259. if (isFinish) {
  260. decodeAAC(input);
  261. }
  262. }
  263. }
  264. if (data.video != null) { //喂视频
  265. if (isFeed) {
  266. jmuxer.feed(data);
  267. }
  268. }
  269. });
  270. }
  271. document.addEventListener("visibilitychange", function () {
  272. if (document.visibilityState == "visible") {
  273. var buffer = RequestIFrame();
  274. ws.send(buffer);
  275. isVisuable = true;
  276. } else {
  277. isVisuable = false;
  278. isFeed = false;
  279. myVideo.pause();
  280. }
  281. });
  282. myVideo.addEventListener('pause', function () {
  283. isFeed = false;
  284. });
  285. var decodeCount = 1;
  286. var player = new PCMPlayer({
  287. encoding: '16bitInt',
  288. channels: 2,
  289. sampleRate: 44100,
  290. flushingTime: 22,
  291. debug: false
  292. });
  293. function handleClose() {
  294. $('.mask').hide();
  295. }
  296. function decodeAAC(data) {
  297. var retPtr = Module._malloc(4 * 5 * 1024); // 接收的数据
  298. var inputPtr = Module._malloc(4 * data.length); // 输入数据
  299. for (var i = 0; i < data.length; i++) {
  300. Module.HEAPU8[(inputPtr) + i] = data[i]; //转换为堆数据
  301. }
  302. var pcmLen = Module._feedData(retPtr, inputPtr, data.length);
  303. if (pcmLen >= 0) {
  304. var pcmData = new Uint8Array(pcmLen);
  305. for (var i = 0; i < pcmLen; i++) {
  306. pcmData[i] = Module.HEAPU8[(retPtr) + i]
  307. }
  308. player.feed(pcmData);
  309. }
  310. decodeCount++;
  311. Module._free(inputPtr);
  312. Module._free(retPtr);
  313. }
  314. //解协议
  315. function ParseProto(data) {
  316. var input = new Uint8Array(data),
  317. duration,
  318. video,
  319. audio;
  320. if (input[0] == 0 && input[1] == 0 && input[2] == 0 && input[3] == 1) {
  321. video = input;
  322. duration = 24;
  323. var nalType = input[4] & 0x1f;
  324. if (!isFeed) {
  325. if (nalType == 0x05 && isVisuable) {
  326. isFeed = true;
  327. }
  328. }
  329. } else if (input[0] == 0xff) {
  330. if (!isEnough) {
  331. requestCount++;
  332. }
  333. audio = input;
  334. if (new Date().getTime() - curTime > 100) {
  335. delayTime = new Date().getTime();
  336. }
  337. curTime = new Date().getTime();
  338. duration = 24;
  339. } else if (input[0] == 0x68) {
  340. if (input[23] == 0x5c) {
  341. console.log("收到消息:" + PrintArry(input));
  342. if (CheckVerifyCode(input)) {
  343. ws.send(ConfigChannel('RK3923C1201900139'));
  344. var checkBuffer = GetScreenState();
  345. ws.send(checkBuffer);
  346. }
  347. else {
  348. $.toast("画面异常,请重新进入", "text");
  349. clearInterval(intervaler);
  350. ws.close();
  351. wsss.close();
  352. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  353. tt.miniProgram.switchTab({
  354. url: '/pages/home/home'
  355. })
  356. }else{
  357. wx.miniProgram.switchTab({
  358. url: '/pages/home/home'
  359. })
  360. }
  361. }
  362. }
  363. if (input[23] == 0x05) { //横竖屏标识
  364. var state = CheckScreenDirection(input.slice(24, 24 + 8));
  365. if (state == 1) {
  366. console.log("安卓卡此时竖屏");
  367. //竖屏处理
  368. resolving = 1;
  369. } else {
  370. console.log("安卓卡此时横屏");
  371. //横屏处理
  372. resolving = 0;
  373. }
  374. }
  375. if (input[23] == 0x0B)//多端登录处理, 数据从索引24开始取, input 是接收到的原始数据
  376. {
  377. var jsonobj = checkMultiLoginInfo(input);
  378. }
  379. }
  380. return {
  381. audio: audio,
  382. video: video,
  383. duration: duration
  384. };
  385. }
  386. function GetRequest() {
  387. var url = location.search; // 获取url中"?"符后的字串
  388. var obj = new Object();
  389. if (url.indexOf("?") != -1) {
  390. var str = url.substr(1);
  391. strs = str.split("&");
  392. for (var i = 0; i < strs.length; i++) {
  393. obj[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
  394. }
  395. }
  396. return obj;
  397. }
  398. function Back() {
  399. ExexuteKeyDown(4);
  400. window.event.returnValue = false;
  401. return false;
  402. }
  403. var url = window.location.href;
  404. url = url.split('/');
  405. var baseUrl = url[0] + '//' + url[2];
  406. var form = {};
  407. form.token = parameters['token'];
  408. form.userCardId = parameters['userCardId'];
  409. function array_unique(arr) {
  410. return arr.filter(function (e, i) {
  411. return arr.indexOf(e) === i;
  412. })
  413. }
  414. var cutList = [];
  415. let timer, isFlag = true;
  416. function showShearPlate() {
  417. stopManyClick(() => {
  418. $('.box-shear-plate').empty();
  419. $.ajax({
  420. url: baseUrl + "/api/public/v5/shear/content",
  421. headers: {
  422. 'Authorization': form.token
  423. },
  424. type: 'get',
  425. dataType: 'json',
  426. success: function (res) {
  427. if (res.status === 0) {
  428. if (res.data.length) {
  429. cutList = array_unique(res.data)
  430. var str = '<div class="title">剪贴板<div onclick="handleClear()" class="btn-clear">清空</div></div><div class="slide-wrapper-content">'
  431. cutList.forEach(function (item) {
  432. str += "<div class='slide-wrapper'><div class='slide-scroll animate-slide-start'><div class='slide-content'><div onclick='handleCopy(\"" + item.content + "\")'>" + item.content + "</div></div><div class='slide-content-button'><button onclick='handleDelete(" + item.id + ")'>删除</button></div></div></div>"
  433. })
  434. str += '</div>'
  435. $('.box-shear-plate').append(str);
  436. } else {
  437. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  438. }
  439. $('.mask').show();
  440. initSlider();
  441. } else {
  442. $('.box-shear-plate').append('<img class="empty" src="img/jianqieban_pic@2x.png" alt="" /><div class="empty-txt">剪贴板为空</div>')
  443. $('.mask').show();
  444. }
  445. }
  446. })
  447. })
  448. }
  449. //防止提示一秒内重复显示
  450. function stopManyClick(fn) {
  451. if (isFlag) {
  452. fn();
  453. }
  454. isFlag = false;
  455. if (timer) { clearTimeout(timer); }
  456. timer = setTimeout(() => { isFlag = true }, 1500);
  457. }
  458. // 清空剪贴板
  459. function handleClear() {
  460. var ids = '';
  461. cutList.forEach(function (item) {
  462. ids += 'ids=' + item.id + '&'
  463. });
  464. ids = ids.substring(0, ids.lastIndexOf('&'));
  465. $.confirm("确定清空剪贴板?", function () {
  466. $.ajax({
  467. url: baseUrl + "/api/public/v5/shear/content?" + ids,
  468. headers: {
  469. 'Authorization': form.token
  470. },
  471. type: 'DELETE',
  472. dataType: 'json',
  473. success: function (res) {
  474. if (res.status === 0) {
  475. showShearPlate();
  476. } else {
  477. $.toast(res.msg, "text");
  478. }
  479. }
  480. })
  481. });
  482. }
  483. function handleCopy(content) {
  484. var cutting = {
  485. "type": "cutting",
  486. "data": {
  487. "str": content
  488. }
  489. };
  490. wsss.send(JSON.stringify(cutting));
  491. }
  492. // 删除剪贴板
  493. function handleDelete(id) {
  494. $.ajax({
  495. url: baseUrl + "/api/public/v5/shear/content?ids=" + id,
  496. headers: {
  497. 'Authorization': form.token
  498. },
  499. type: 'DELETE',
  500. dataType: 'json',
  501. success: function (res) {
  502. if (res.status === 0) {
  503. showShearPlate();
  504. } else {
  505. $.toast(res.msg, "text");
  506. }
  507. }
  508. })
  509. }
  510. function initSlider() {
  511. //手指滑动多少距离就认为是滑成功
  512. //这个值不能太大,否则影响斜着滑动时,垂直滑动的流畅性,也不能太小,太灵敏也不好
  513. var diffXDistance = 50;
  514. //当前滑动的对象
  515. var currentObject;
  516. //上一次滑动的对象
  517. var lastObject;
  518. //是否可以左右滑动,在上下滑的时候禁止左右滑
  519. var canSlide = true;
  520. //用于记录按下的点
  521. var startPoint;
  522. $(".slide-content").css({
  523. width: $(".slide-wrapper").width()
  524. });
  525. document.body.removeEventListener('touchmove', function (e) {
  526. e.preventDefault()
  527. }, {
  528. passive: false
  529. })
  530. $(".slide-scroll").css({
  531. width: $(".slide-wrapper").width() + $(".slide-content-button").width()
  532. }).on('touchstart', function (e) {
  533. currentObject = this;
  534. startPoint = {
  535. x: e.originalEvent.changedTouches[0].pageX,
  536. y: e.originalEvent.changedTouches[0].pageY
  537. };
  538. }).on('touchmove', function (e) {
  539. //如果是左右滑动,就禁止上下的滑动
  540. //如果是上下的滑动,就禁止左右滑动
  541. if (Math.abs(e.originalEvent.changedTouches[0].pageX - startPoint.x) > Math.abs(e.originalEvent.changedTouches[0].pageY - startPoint.y)) {
  542. event.preventDefault();
  543. } else {
  544. canSlide = false;
  545. }
  546. }).on('touchend', function (e) {
  547. //如果是上下滑动,这里就直接返回了
  548. if (!canSlide) {
  549. canSlide = true;
  550. return true;
  551. }
  552. //点击除当前左滑对象之外的任意其他位置
  553. if (lastObject && currentObject != lastObject) {
  554. //右滑→
  555. $(lastObject).removeClass("animate-slide");
  556. //清空上一个左滑的对象
  557. lastObject = undefined;
  558. }
  559. var diffX = e.originalEvent.changedTouches[0].pageX - startPoint.x;
  560. if (diffX < -diffXDistance) {
  561. //左滑←
  562. $(currentObject).addClass("animate-slide");
  563. if (lastObject && lastObject != currentObject) {
  564. //右滑→
  565. $(lastObject).removeClass("animate-slide");
  566. }
  567. //记录上一个左滑的对象
  568. lastObject = currentObject;
  569. } else if (diffX >= diffXDistance) {
  570. if (currentObject == lastObject) {
  571. //右滑→
  572. $(currentObject).removeClass("animate-slide");
  573. //清空上一个左滑的对象
  574. lastObject = undefined;
  575. }
  576. }
  577. });
  578. }
  579. var orientation = 0; //0 竖屏,1横屏
  580. var btnMuted = document.querySelector("#btnMuted");
  581. btnMuted && (function () {
  582. var setHistory = function (left, top) {
  583. try {
  584. localStorage.setItem("muted-btn-loc", JSON.stringify({
  585. left: left,
  586. top: top
  587. }));
  588. } catch (ex) { }
  589. };
  590. var getHistory = function () {
  591. try {
  592. var value = localStorage.getItem("muted-btn-loc");
  593. if (!value) return null;
  594. value = JSON.parse(value);
  595. if (!value) return null;
  596. return value;
  597. } catch (ex) {
  598. return null
  599. }
  600. };
  601. var fixLoc = function (loc) {
  602. var rect = btnMuted.getBoundingClientRect();
  603. rect = {
  604. top: rect.top,
  605. left: rect.left,
  606. width: rect.width,
  607. height: rect.height
  608. }; //部分低版本浏览器,该属性为只读
  609. if (loc) {
  610. rect.left = loc.left;
  611. rect.top = loc.top;
  612. }
  613. var minX = 0;
  614. var minY = 0;
  615. var docRect = document.documentElement.getBoundingClientRect();
  616. var maxY = docRect.height - rect.height;
  617. var maxX = docRect.width - rect.width;
  618. var left = rect.left;
  619. var top = rect.top;
  620. left = Math.min(left, maxX);
  621. left = Math.max(left, minX);
  622. top = Math.min(top, maxY);
  623. top = Math.max(top, minY);
  624. if (loc || top !== rect.top || left !== rect.left) {
  625. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  626. }
  627. }
  628. window.addEventListener("resize", function () {
  629. fixLoc();
  630. });
  631. var touchPoint = {
  632. pageY: 0,
  633. pageX: 0
  634. };
  635. var currentLoc = {
  636. top: 0,
  637. left: 0,
  638. curTop: 0,
  639. curLeft: 0
  640. };
  641. var toMove = false;
  642. var touchmove = function (e) {
  643. e.preventDefault();
  644. var point = e.changedTouches[0];
  645. var top = -touchPoint.pageY + point.pageY;
  646. var left = -touchPoint.pageX + point.pageX;
  647. if (toMove) {
  648. top += currentLoc.top;
  649. left += currentLoc.left;
  650. currentLoc.curLeft = left;
  651. currentLoc.curTop = top;
  652. btnMuted.style.cssText += "left:" + left + "px;top:" + top + "px;";
  653. } else {
  654. if (Math.abs(top) >= 5 || Math.abs(left) >= 5) {
  655. toMove = true;
  656. }
  657. }
  658. };
  659. var touchend = function () {
  660. window.removeEventListener("touchmove", touchmove, {
  661. passive: false
  662. });
  663. window.removeEventListener("touchend", touchend, {
  664. passive: false
  665. });
  666. if (toMove) {
  667. setHistory(currentLoc.curLeft, currentLoc.curTop);
  668. fixLoc();
  669. } else {
  670. //按点击处理
  671. var set = $('.control-right-img').attr("data-id")
  672. if (set == '1') {
  673. $('.control-right-img').attr({
  674. "data-id": "2"
  675. })
  676. $(".leftmains").css({
  677. "right": "0rem"
  678. })
  679. } else {
  680. $('.control-right-img').attr({
  681. "data-id": "1"
  682. })
  683. $(".leftmains").css({
  684. "right": "-4rem"
  685. })
  686. }
  687. }
  688. }
  689. btnMuted.addEventListener("touchstart", function (e) {
  690. e.preventDefault();
  691. toMove = false;
  692. var point = e.changedTouches[0];
  693. touchPoint.pageX = point.pageX;
  694. touchPoint.pageY = point.pageY;
  695. var rect = e.target.getBoundingClientRect();
  696. currentLoc.top = rect.top;
  697. currentLoc.left = rect.left;
  698. window.addEventListener("touchmove", touchmove, {
  699. passive: false
  700. });
  701. window.addEventListener("touchend", touchend, {
  702. passive: false
  703. });
  704. }, {
  705. passive: false
  706. });
  707. var history = getHistory();
  708. if (history) {
  709. fixLoc(history);
  710. }
  711. btnMuted.classList.remove("hide");
  712. })();
  713. $(".boximg").on("click", function () {
  714. $(".mainbox").css({
  715. "display": "none"
  716. })
  717. })
  718. // 剪贴板
  719. $(".sboxbu").on("click", function () {
  720. $(".sbox").css({
  721. "display": "none"
  722. })
  723. })
  724. // 剪贴板
  725. $(".uploadss").on("click", function () {
  726. $(".sbox").css({
  727. "display": "none"
  728. })
  729. })
  730. $("#upload").on("click", function () {
  731. clearInterval(intervaler);
  732. ws.close();
  733. wsss.close();
  734. if(navigator.userAgent.toLowerCase().includes('toutiaomicroapp')){
  735. tt.miniProgram.switchTab({
  736. url: '/pages/home/home'
  737. })
  738. }else{
  739. wx.miniProgram.switchTab({
  740. url: '/pages/home/home'
  741. })
  742. }
  743. })
  744. function selectText(x) {
  745. if (document.selection) {
  746. var range = document.body.createTextRange();
  747. range.moveToElementText(x);
  748. range.select();
  749. } else if (window.getSelection) {
  750. var selection = window.getSelection();
  751. var range = document.createRange();
  752. selection.removeAllRanges();
  753. range.selectNodeContents(x);
  754. selection.addRange(range);
  755. }
  756. }
  757. function cp(x) {
  758. $(".mainbox").css({
  759. "display": "none"
  760. })
  761. $(".sbox").css({
  762. "display": "block"
  763. })
  764. selectText(x);
  765. document.execCommand("copy");
  766. }
  767. window.onbeforeunload = function () {
  768. ws.close();
  769. wsss.close();
  770. }
  771. </script>
  772. <script type="text/javascript" src="aac.js"></script>
  773. </body>
  774. </html>