Skip to content

Commit 09b2726

Browse files
history items injection (10 entries)
1 parent dc976b9 commit 09b2726

File tree

7 files changed

+35
-23
lines changed

7 files changed

+35
-23
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Assets
44
- [kutt.it API](https://github.com/thedevs-network/kutt#api) is used to retreive shortened URLs.
5+
- [node-kutt](https://github.com/ardalanamini/node-kutt) is used for API calls
56

67
## Development
78
- `npm install` to install dependencies.
@@ -53,6 +54,9 @@ height="50">](https://github.com/abhijithvijayan/kutt-extension/releases)
5354
- [x] Fix UI issues in Firefox
5455
- [x] Using Node-Kutt package(feature request)
5556
- [ ] History Feature
57+
- [ ] Context Menu
58+
- [ ] Auto Copy Clipboard
59+
- [ ] Toggleable Options
5660

5761

5862
## Note:

src/history.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ <h2 class="table__content--title">Recent shortened links.</h2>
2626
</tr>
2727
</thead>
2828
<tbody class="table__content--body">
29-
<tr class="table__body--holder">
29+
<!-- TEMPLATE TO USE -->
30+
<!-- <tr class="table__body--holder">
3031
<td class="table__body--original">
3132
<a href="#" class="table__body--originalURL" target="_blank" rel="noopener">https://google.com</a>
3233
</td>
@@ -48,7 +49,7 @@ <h2 class="table__content--title">Recent shortened links.</h2>
4849
</button>
4950
</div>
5051
</td>
51-
</tr>
52+
</tr> -->
5253
</tbody>
5354
</table>
5455
</div>

src/manifest.chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "Kutt",
4-
"version": "0.8.0",
4+
"version": "0.9.0",
55
"description": "URL Shortener",
66
"icons": {
77
"16": "assets/favicon-16.png",

src/manifest.firefox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "Kutt",
4-
"version": "0.8.0",
4+
"version": "0.9.0",
55
"browser_specific_settings": {
66
"gecko": {
77

src/manifest.opera.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "Kutt",
4-
"version": "0.8.0",
4+
"version": "0.9.0",
55
"description": "URL Shortener",
66
"developer": {
77
"name": "abhijithvijayan"

src/scripts/background.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Kutt from 'kutt';
22
import browser from 'webextension-polyfill';
33

4-
let count = 0, sample = [];
4+
let count = 0, URLs_array = [];
55

66
// Shorten url
77
async function getShortURL(API_key, URLtoShorten, password) {
@@ -42,23 +42,19 @@ browser.runtime.onMessage.addListener(async (request, sender, response) => {
4242
}
4343
// store urls to history
4444
if (request.msg === 'store') {
45-
// get the object
46-
console.log(request.URLs);
47-
console.log(count);
48-
// sample.push(request.URLs);
49-
if (count >= 3) {
45+
// console.log(request.URLs);
46+
// console.log(count);
47+
if (count >= 10) {
5048
// delete first element
51-
sample.shift();
49+
URLs_array.shift();
5250
--count;
5351
browser.storage.local.set({ count: count });
5452
}
55-
if (count < 3) {
56-
sample.push(request.URLs);
57-
browser.storage.local.set({ URL_array: sample, count: ++count });
58-
console.log(sample);
53+
if (count < 10) {
54+
URLs_array.push(request.URLs);
55+
browser.storage.local.set({ URL_array: URLs_array, count: ++count });
56+
// console.log(URLs_array);
5957
}
60-
// store upto 10
61-
// console.log(count);
6258
}
6359

6460

src/scripts/history.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import browser from 'webextension-polyfill';
22

3-
// get longURL, shortURL
4-
browser.storage.local.get(['URL_array', 'count']).then(result => {
5-
console.log(result.URL_array);
6-
});
73

8-
// update DOM
4+
// on page load
5+
document.addEventListener('DOMContentLoaded', () => {
6+
let updatedHTML, html = '<tr class="table__body--holder"><td class="table__body--original"><a href="%longLink%" class="table__body--originalURL" target="_blank" rel="noopener">%longLink%</a></td><td class="table__body--shortened"><div class="table__body--shortenBody"><button class="table__body--copyBtn" title="Copy"><img id="" class="selectDisable icon__img" src="assets/copy.svg" alt="copy" /></button><a href="%shortLink%" class="table__body--shortenURL" target="_blank" rel="noopener">%shortLink%</a></div></td><td class="table__body--functionBtns"><div class="table__body--btnHolder"><button class="table__body--qrcode" title="QR Code"><img id="" class="selectDisable icon__img" src="assets/qrcode.svg" alt="QR Code" /></button><button class="table__body--delete" title="Delete"><img id="" class="selectDisable icon__img" src="assets/delete.svg" alt="Delete" /></button></div></td></tr>';
7+
// get longURL, shortURL
8+
browser.storage.local.get(['URL_array', 'count']).then(result => {
9+
// console.log(result.URL_array);
10+
// update DOM
11+
for (let el of result.URL_array) {
12+
// Regular Expression Based Implementation
13+
updatedHTML = html.replace(/%longLink%/g, el.longUrl);
14+
updatedHTML = updatedHTML.replace(/%shortLink%/g, el.shortUrl);
15+
// inject to DOM
16+
document.querySelector('.table__content--body').insertAdjacentHTML('afterbegin', updatedHTML);
17+
}
18+
});
19+
});
920

1021
// copy button
1122

0 commit comments

Comments
 (0)