history.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>历史记录</title>
  6. <link rel="stylesheet" href="./public/css/browser.css">
  7. </head>
  8. <body style="overflow: hidden">
  9. <section style="-webkit-app-region: drag;height: 55px" class="bowerHeader">
  10. <section style="-webkit-app-region: no-drag" class="browerHeaderControl clearfix">
  11. <button type="button" class="icon-times close" style="font-size:16px;background: none;color: #fff"></button>
  12. </section>
  13. <div class="HistoryMain">
  14. <div class="HistoryHead">
  15. <p>历史记录</p>
  16. <div class="HistorySelect">
  17. <div>
  18. <input type="text" id="SelectInp" placeholder="搜索历史记录" onblur="inputblur()" onclick="inputclick()" style="-webkit-app-region: no-drag" value="">
  19. </div>
  20. </div>
  21. </div>
  22. <div class="HistoryContainer">
  23. </div>
  24. <div class="Historyoperating">
  25. <ul>
  26. <li onclick="xianshi()" style="border-bottom: 2px solid #dadada">显示历史记录</li>
  27. <li onclick="HistoryCancelAll()" id="qingchu">
  28. 清除历史记录
  29. <div class="item" onclick="HistoryCancelDone()" style="opacity: 0">确定</div>
  30. <div class="item" style="opacity: 0">取消</div>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. <div class="CampusInfoBrowserHistory"></div>
  36. <div class="HistoryBottom">
  37. <div class="HistoryBottomContent">
  38. <div class="Historycount">已选择<span class="HistoryCountSpan">1</span>项</div>
  39. <div class="HistoryPick">
  40. <div style="margin-right: 20px;" onclick="HistoryCancel()">取消</div>
  41. <div onclick="HistoryDelect()">删除</div>
  42. </div>
  43. </div>
  44. </div>
  45. </section>
  46. <script src="./public/js/uform.js"></script>
  47. <script>
  48. var isclick = false
  49. var ipc=require('electron').ipcRenderer;
  50. $(".close")[0].onclick=function(){
  51. ipc.send('BrowserHistory-close');
  52. };
  53. addChild = function(parent,newChild){
  54. parent.insertBefore(newChild,parent.firstChild);
  55. // if(parent.firstChild){
  56. // // parent.insertBefore(newChild,parent.firstChild);
  57. // } else {
  58. // // parent.addChild(newChild);
  59. // }
  60. return parent;
  61. }
  62. const inputblur = () => {
  63. isclick = false
  64. }
  65. const inputclick = () => {
  66. isclick = true
  67. }
  68. const choose = () => {
  69. let numb = document.querySelectorAll("input[type='checkbox']:checked").length
  70. if (numb === 0) {
  71. $('.HistoryBottom')[0].style.bottom = '-55px';
  72. }else{
  73. $('.HistoryBottom')[0].style.bottom = '-0px';
  74. $('.HistoryCountSpan')[0].innerText = numb
  75. }
  76. }
  77. const HistoryCancel = () => {
  78. let numb = document.querySelectorAll("input[type='checkbox']:checked")
  79. if (numb.length) {
  80. for(var i=0; i < numb.length; i++){
  81. numb[i].checked = false;
  82. }
  83. $('.HistoryBottom')[0].style.bottom = '-55px';
  84. $('.HistoryCountSpan')[0].innerText = '0'
  85. }
  86. }
  87. const HistoryDelect = () => {
  88. let isclick = document.querySelectorAll("input[type='checkbox']:checked")
  89. for(let i = 0; i < isclick.length; i ++){
  90. Historyshanchu(isclick[i].parentNode.parentNode.parentNode.childNodes[0].innerHTML, isclick[i].value, isclick[i].parentNode)
  91. }
  92. }
  93. const Historyshanchu = (par, item, my) => {
  94. let arr = JSON.parse(localStorage[par])
  95. arr.splice(~~item, 1)
  96. localStorage[par] = JSON.stringify(arr)
  97. my.style.display = 'none'
  98. my.parentNode.removeChild(my)
  99. $('.HistoryBottom')[0].style.bottom = '-55px';
  100. $('.HistoryCountSpan')[0].innerText = '0'
  101. }
  102. const HistoryCancelAll = () => {
  103. [...document.querySelectorAll('.item')].map((i)=>{
  104. if(i.style.opacity === '0'){
  105. i.style.opacity = '1'
  106. }else{
  107. i.style.opacity = '0'
  108. }
  109. })
  110. }
  111. const HistorySelect = () => {
  112. let selectdata = document.querySelectorAll('#SelectInp')[0]
  113. let arr = []
  114. for (date in localStorage) {
  115. let data = JSON.parse(localStorage[date])
  116. for(let i = 0; i < data.length; i ++){
  117. if(data[i].title.indexOf(selectdata.value) >= 0 || data[i].url.indexOf(selectdata.value) >= 0){
  118. arr.push(data[i])
  119. }
  120. }
  121. }
  122. xuanrang(arr)
  123. }
  124. let BrowserHistory = $(".HistoryContainer")[0];
  125. const xuanrang = (arr) => {
  126. BrowserHistory.innerHTML = ''
  127. let a = $$("div",{"className":"HistoryCard"},BrowserHistory);
  128. var a_head=$$("p",{"className":"HistoryCardHead","innerText":'搜索历史记录'},a);
  129. var a_container=$$("ul",{"className":"HistoryCardContainer"},a);
  130. // addChild(BrowserHistory,a);
  131. for(let i=0;i<arr.length;i++){
  132. let a_list=$$("li",{},a_container);
  133. let a_time=$$("span",{"innerText":arr[i].time},a_list);
  134. let a_content=$$("div",{},a_list);
  135. $$("img",{"src":arr[i].favicons,"draggable":"false"},a_content);
  136. $$("p",{"innerText":arr[i].title},a_content);
  137. $$("p",{"innerText":arr[i].url}, a_content)
  138. a_content.url=arr[i].url;
  139. a_content.onclick=function () {
  140. ipc.send('open-history',this.url);
  141. ipc.send('BrowserHistory-close');
  142. }
  143. }
  144. }
  145. const xianshi = () => {
  146. BrowserHistory.innerHTML = ''
  147. for (date in localStorage) {
  148. var a = $$("div",{"className":"HistoryCard"});
  149. addChild(BrowserHistory,a);
  150. if(date != "arr"){
  151. var a_head=$$("p",{"className":"HistoryCardHead","innerText":date},a);
  152. var a_container=$$("ul",{"className":"HistoryCardContainer"},a);
  153. var data = JSON.parse(localStorage[date]);
  154. for(var i=0;i<data.length;i++){
  155. var a_list=$$("li",{},a_container);
  156. $$("input",{"type":"checkbox","className":"Historyinput",'value': i,'onclick':function () {
  157. choose()
  158. }},a_list)
  159. var a_time=$$("span",{"innerText":data[i].time},a_list);
  160. var a_content=$$("div",{},a_list);
  161. $$("img",{"src":data[i].favicons,"draggable":"false"},a_content);
  162. $$("p",{"innerText":data[i].title},a_content);
  163. $$("p",{"innerText":data[i].url}, a_content)
  164. a_content.url=data[i].url;
  165. a_content.onclick=function () {
  166. ipc.send('open-history',this.url);
  167. ipc.send('BrowserHistory-close');
  168. }
  169. }
  170. }
  171. }
  172. }
  173. const HistoryCancelDone = () => {
  174. localStorage = ''
  175. }
  176. const keydown = () => {
  177. document.onkeydown=function(event){
  178. var e = event || window.event || arguments.callee.caller.arguments[0];
  179. if(e && e.keyCode==13){
  180. //要做的事情
  181. if(isclick == true){
  182. HistorySelect()
  183. }
  184. }
  185. };
  186. }
  187. window.onload = () => {
  188. xianshi()
  189. keydown()
  190. }
  191. </script>
  192. </body>
  193. </html>