|
@@ -1,11 +1,137 @@
|
|
-chrome.runtime.onMessage.addListener(
|
|
|
|
- function (request, sender, sendResponse) {
|
|
|
|
- window.alert(JSON.stringify(document))
|
|
|
|
|
|
+// chrome.runtime.onMessage.addListener(
|
|
|
|
+// function (request, sender, sendResponse) {
|
|
|
|
+// window.alert(JSON.stringify(document))
|
|
|
|
+// }
|
|
|
|
+// );
|
|
|
|
+
|
|
|
|
+$(function(){
|
|
|
|
+ let isMarking = false;
|
|
|
|
+ let currentColor = "#dff209";
|
|
|
|
+ let anchorOffset = 0;
|
|
|
|
+ let currentSelectObj ={};
|
|
|
|
+ document.onmouseup =() =>{
|
|
|
|
+ var selectObj = window.getSelection()
|
|
|
|
+ let temSelectObj = getSelectobj(selectObj);
|
|
|
|
+ var tempdt = getColumnName(selectObj.anchorNode);
|
|
|
|
+ if(tempdt != undefined && selectObj.toString()!=''){
|
|
|
|
+ currentSelectObj = temSelectObj;
|
|
|
|
+ currentSelectObj.color = currentColor;
|
|
|
|
+ currentSelectObj.Type = 0;
|
|
|
|
+ // currentSelectObj.patentNo = this.patent.publicNo
|
|
|
|
+ // this.showPizhu();
|
|
|
|
+
|
|
|
|
+ isMarking = true;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ currentSelectObj = {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ console.log(currentSelectObj)
|
|
|
|
+ // chrome.runtime.sendMessage('highlight', (response) => {
|
|
|
|
+ // console.log('received user data', response);
|
|
|
|
+ // });
|
|
|
|
+ }
|
|
|
|
+ function getSelectobj(selectObj){
|
|
|
|
+ var temNode = selectObj.anchorNode;
|
|
|
|
+ var a = temNode.parentElement
|
|
|
|
+ NotIncludeDataType(a)
|
|
|
|
+ function NotIncludeDataType(node){
|
|
|
|
+ if (node.getAttribute("data-type") != null) {
|
|
|
|
+ temNode = node
|
|
|
|
+ } else {
|
|
|
|
+ NotIncludeDataType(node.parentElement);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ let index =0;
|
|
|
|
+ getColumn(temNode,selectObj);
|
|
|
|
+
|
|
|
|
+ return {"Id":uuid(),"column":temNode.getAttribute("data-type"),"index":anchorOffset,"text":selectObj.toString(),'temNode':temNode};
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ function uuid() {
|
|
|
|
+ var s = [];
|
|
|
|
+ var hexDigits = "0123456789abcdef";
|
|
|
|
+ for (var i = 0; i < 36; i++) {
|
|
|
|
+ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
}
|
|
}
|
|
- );
|
|
|
|
|
|
+ s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
|
|
+ s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
|
|
+ s[8] = s[13] = s[18] = s[23] = "-";
|
|
|
|
+
|
|
|
|
+ var uuid = s.join("");
|
|
|
|
+ return uuid;
|
|
|
|
+ }
|
|
|
|
+ function getColumnName(el){
|
|
|
|
+ let root = el;
|
|
|
|
+
|
|
|
|
+ if(el == undefined){
|
|
|
|
+ return undefined;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!(el instanceof HTMLElement)){
|
|
|
|
+ root = el.parentElement;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ let dt = root.getAttribute("data-Type");
|
|
|
|
+
|
|
|
|
+ if (dt != undefined){
|
|
|
|
+ return root;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return dt = getColumnName(root.parentElement);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ function getColumn(node,selectObj){
|
|
|
|
+ if(node != selectObj.anchorNode){
|
|
|
|
+ if(node.nodeValue != null ){
|
|
|
|
+ anchorOffset += node.nodeValue.trim().length;
|
|
|
|
+ }
|
|
|
|
+ let iIndex =0;
|
|
|
|
+ while(iIndex<node.childNodes.length){
|
|
|
|
+ if(getColumn(node.childNodes[iIndex],selectObj)){
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ iIndex +=1;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(selectObj.anchorNode.nodeValue!=null){
|
|
|
|
+ if(selectObj.extentOffset>=selectObj.anchorOffset){
|
|
|
|
+ anchorOffset += selectObj.anchorOffset - selectObj.anchorNode.nodeValue.length + selectObj.anchorNode.nodeValue.trimStart().length;
|
|
|
|
+ }else{
|
|
|
|
+ anchorOffset += selectObj.extentOffset - selectObj.extentNode.nodeValue.length + selectObj.extentNode.nodeValue.trimStart().length;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+ // chrome.runtime.onConnect.addListener(function(msg) {
|
|
|
|
+ // console.log(msg)
|
|
|
|
+ // console.assert(port.name == "knockknock");
|
|
|
|
+ // port.onMessage.addListener(function(msg) {
|
|
|
|
+ // console.log(msg)
|
|
|
|
+ // if (msg.joke == "Knock knock")
|
|
|
|
+ // port.postMessage({question: "Who's there?"});
|
|
|
|
+ // else if (msg.answer == "Madame")
|
|
|
|
+ // port.postMessage({question: "Madame who?"});
|
|
|
|
+ // else if (msg.answer == "Madame... Bovary")
|
|
|
|
+ // port.postMessage({question: "I don't get it."});
|
|
|
|
+ // });
|
|
|
|
+ // });
|
|
|
|
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {//监听扩展程序进程或内容脚本发送请求的请求
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {//监听扩展程序进程或内容脚本发送请求的请求
|
|
|
|
+ // window.alert(JSON.stringify(document))
|
|
|
|
+
|
|
console.log('content', request, sender);
|
|
console.log('content', request, sender);
|
|
|
|
+ sendResponse({title:'传送'})
|
|
|
|
+ return true;
|
|
|
|
+ // render(1)
|
|
// const {
|
|
// const {
|
|
// inputColorValue,
|
|
// inputColorValue,
|
|
// titleValue,
|
|
// titleValue,
|