history.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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="" onkeyup="openFlag()" onkeydown="closeFlag()" >
  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. if(data[i].data) {
  119. var a = date.split('/')
  120. a.splice(1,0,'年')
  121. a.splice(3,0,'月')
  122. a.push('日')
  123. a = a.join('')
  124. data[i].time = a
  125. arr.push(data[i])
  126. }
  127. }
  128. }
  129. }
  130. xuanrang(arr)
  131. }
  132. let BrowserHistory = $(".HistoryContainer")[0];
  133. const xuanrang = (arr) => {
  134. BrowserHistory.innerHTML = ''
  135. let a = $$("div",{"className":"HistoryCard"},BrowserHistory);
  136. var a_head=$$("p",{"className":"HistoryCardHead","innerText":'搜索历史记录'},a);
  137. var a_container=$$("ul",{"className":"HistoryCardContainer"},a);
  138. // addChild(BrowserHistory,a);
  139. for(let i=0;i<arr.length;i++){
  140. let a_list=$$("li",{},a_container);
  141. let a_time=$$("span",{"innerText":arr[i].time},a_list);
  142. let a_content=$$("div",{},a_list);
  143. $$("img",{"src":arr[i].favicons,"draggable":"false"},a_content);
  144. $$("p",{"innerText":arr[i].title},a_content);
  145. $$("p",{"innerText":arr[i].url}, a_content)
  146. a_content.url=arr[i].url;
  147. a_content.onclick=function () {
  148. ipc.send('open-history',this.url);
  149. ipc.send('BrowserHistory-close');
  150. }
  151. }
  152. }
  153. const xianshi = () => {
  154. BrowserHistory.innerHTML = ''
  155. for (date in localStorage) {
  156. var a = $$("div",{"className":"HistoryCard"});
  157. addChild(BrowserHistory,a);
  158. if(date != "arr"){
  159. var a_head=$$("p",{"className":"HistoryCardHead","innerText":date},a);
  160. var a_container=$$("ul",{"className":"HistoryCardContainer"},a);
  161. var data = JSON.parse(localStorage[date]).reverse();
  162. for(var i=0;i<data.length;i++){
  163. var a_list=$$("li",{},a_container);
  164. var a_time=$$("span",{"innerText":data[i].time},a_list);
  165. $$("input",{"type":"checkbox","className":"Historyinput",'value': i,'onclick':function () {
  166. choose()
  167. }},a_time)
  168. var a_content=$$("div",{},a_list);
  169. $$("img",{"src":data[i].favicons,"draggable":"false"},a_content);
  170. $$("p",{"innerText":data[i].title},a_content);
  171. $$("p",{"innerText":data[i].url}, a_content)
  172. a_content.url=data[i].url;
  173. a_content.onclick=function () {
  174. ipc.send('open-history',this.url);
  175. ipc.send('BrowserHistory-close');
  176. }
  177. }
  178. }
  179. }
  180. }
  181. const HistoryCancelDone = () => {
  182. localStorage = ''
  183. }
  184. const keydown = () => {
  185. document.onkeydown=function(event){
  186. var e = event || window.event || arguments.callee.caller.arguments[0];
  187. if(e && e.keyCode == 13){
  188. //要做的事情
  189. if(isclick == true && $('#SelectInp')[0].value.length != 0){
  190. HistorySelect()
  191. }
  192. }
  193. if(e && e.keyCode == 8){
  194. if($('#SelectInp')[0].value.length == 1) {
  195. xianshi()
  196. }
  197. }
  198. };
  199. }
  200. var flag = 0;
  201. var t;
  202. const openFlag = () => {
  203. t = setTimeout(() => {flag = 1; dosomething();}, 1000);
  204. }
  205. const closeFlag = () => {
  206. clearTimeout(t);
  207. flag = 0;
  208. }
  209. const dosomething = () => {
  210. if (flag && $('#SelectInp')[0].value.length != 0) {
  211. HistorySelect()
  212. }
  213. }
  214. window.onload = () => {
  215. xianshi()
  216. keydown()
  217. }
  218. </script>
  219. </body>
  220. </html>