File size: 2,456 Bytes
2319518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa4486a
2319518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f36f70
 
 
 
 
 
2319518
0f36f70
2319518
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

function getPageTextContent() {
  var textContent = document.body.textContent;
  return textContent;
}

function cache_browser(){
  const body = document.querySelector('html');
  const text = body.innerHTML;
  console.log(text);
  chrome.runtime.sendMessage({ data: text , close: true , flag: 'open_tab_and_cache_from_content', type: 'html'});

}

const floatingBox = document.createElement('div');
floatingBox.style.position = 'fixed';
floatingBox.style.bottom = '650px';
floatingBox.style.right = '60px';
floatingBox.style.width = '125px';
floatingBox.style.height = '55px';
floatingBox.style.backgroundColor = '#f2f2f2';
floatingBox.style.border = '1px solid black';
floatingBox.style.borderRadius = '5px';
floatingBox.style.padding = '10px';
floatingBox.style.zIndex = '9999';

const button = document.createElement('button');
button.style.position = 'fixed';
button.style.top = '30px';
button.style.right = '30px';
button.style.zIndex = "9999";
button.textContent = "Add to LLMBB's Reading List";
button.style.fontFamily = 'Arial, sans-serif';
button.style.fontSize = '14px';
button.style.width = '140px';
button.style.height = '60px';
button.style.backgroundColor = '#695DE8';
button.style.color = 'white';
button.style.borderRadius = '5px';
button.style.border = '0px';
button.style.whiteSpace = 'pre-wrap';
button.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.2)';

floatingBox.appendChild(button);

document.body.appendChild(button);

let isDragging = false;
var isMouseReleased = false;
let initialX;
let initialY;

button.addEventListener('mousedown', (e) => {
  isDragging = true;
  initialX = e.clientX;
  initialY = e.clientY;
});

document.addEventListener('mousemove', (e) => {
  if (isDragging) {
    const dx = e.clientX - initialX;
    const dy = e.clientY - initialY;
    button.style.right = `${parseFloat(button.style.right) - dx}px`;
    button.style.top = `${parseFloat(button.style.top) + dy}px`;
    initialX = e.clientX;
    initialY = e.clientY;
    isMouseReleased = true;
  }
});

document.addEventListener('mouseup', (e) => {
  isDragging = false;

});

button.addEventListener('click', (e) => {
  if (isMouseReleased) {
    isMouseReleased = false;
    e.stopPropagation();
  } else {
      try {
        var result = confirm("Are you sure to ask LLMBB to remember this page?");
        if (result) {
          cache_browser()
        }
      }catch (error) {
      cache_browser()
      console.error(error);
    }
  }
});