big update
This commit is contained in:
parent
9b739ce81f
commit
94ac8f53a2
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.png
|
||||||
|
config.js
|
6
config.js.example
Normal file
6
config.js.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
var config = {
|
||||||
|
shlinkUrl: 'https://example.com',
|
||||||
|
shlinkOutUrl : 'https://example.com',
|
||||||
|
shlinkAppUrl : 'https://app.shlink.io/server/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||||
|
shlinkApiKey: 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
"service_worker": "background.js"
|
"service_worker": "background.js"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"default_icon": "assets/icon.png",
|
"default_icon": "assets/my-icon.png",
|
||||||
"default_title": "redirect",
|
"default_title": "redirect",
|
||||||
"default_popup": "popup.html"
|
"default_popup": "popup.html"
|
||||||
},
|
},
|
||||||
|
@ -1,35 +1,7 @@
|
|||||||
const searchButton = document.getElementById('searchButton');
|
function newRedirect () {
|
||||||
if (searchButton) {
|
|
||||||
searchButton.addEventListener('click', () => {
|
|
||||||
searchRedirect();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const newButton = document.getElementById('newButton');
|
|
||||||
if (newButton) {
|
|
||||||
newButton.addEventListener('click', () => {
|
|
||||||
newRedirect();
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function searchRedirect() {
|
|
||||||
const request = new XMLHttpRequest();
|
|
||||||
const url = 'https://url.example.com/rest/v3/short-urls';
|
|
||||||
request.open('GET', url);
|
|
||||||
request.setRequestHeader('X-Api-Key', 'apikeyhere');
|
|
||||||
request.send();
|
|
||||||
request.onload = (e) => {
|
|
||||||
var shortUrls = request.response
|
|
||||||
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
|
|
||||||
let url = tabs[0].url;
|
|
||||||
alert(shortUrls)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function newRedirect() {
|
|
||||||
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
|
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
|
||||||
let currentUrl = tabs[0].url;
|
let currentUrl = tabs[0].url;
|
||||||
const url = 'https://url.example.com/rest/v3/short-urls';
|
const url = `${config.shlinkUrl}/rest/v3/short-urls`;
|
||||||
let sendData = {
|
let sendData = {
|
||||||
"longUrl": currentUrl,
|
"longUrl": currentUrl,
|
||||||
"tags": ["Added by BOTv1"]
|
"tags": ["Added by BOTv1"]
|
||||||
@ -37,12 +9,15 @@ function newRedirect() {
|
|||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open('POST', url);
|
request.open('POST', url);
|
||||||
request.setRequestHeader('accept', 'application/json');
|
request.setRequestHeader('accept', 'application/json');
|
||||||
request.setRequestHeader('X-Api-Key', 'apikeyhere');
|
request.setRequestHeader('X-Api-Key', `${config.shlinkApiKey}`);
|
||||||
request.setRequestHeader('Content-type', 'application/json');
|
request.setRequestHeader('Content-type', 'application/json');
|
||||||
request.send(JSON.stringify(sendData));
|
request.send(JSON.stringify(sendData));
|
||||||
request.onload = (e) => {
|
request.onload = (e) => {
|
||||||
var responseData = request.response;
|
var shortUrlOut = document.getElementById("output-shortUrl")
|
||||||
document.getElementById("p1link").innerHTML = responseData;
|
var responseData = JSON.parse(request.response);
|
||||||
|
shortUrlOut.value = `${config.shlinkOutUrl}/${responseData.shortCode}`;
|
||||||
|
var shlinkAppBtnRdUrl = `${config.shlinkAppUrl}/short-code/${responseData.shortCode}/visits`;
|
||||||
|
document.getElementById("p1qr-code").src = `${config.shlinkUrl}/${responseData.shortCode}/qr-code?size=160&format=png&margin=2&errorCorrection=L`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
16
popup.css
16
popup.css
@ -1,22 +1,22 @@
|
|||||||
.container {
|
.container {
|
||||||
width: 360px;
|
width: 420px;
|
||||||
color: #314d3e;
|
color: #314d3e;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.textbox {
|
.textbox {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0px 2px;
|
padding: 0px 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.textbox:focus {
|
.textbox:focus {
|
||||||
outline: 0;
|
outline: 0;
|
||||||
border-color: #66afe9;
|
border-color: #66afe9;
|
||||||
}
|
}
|
13
popup.html
13
popup.html
@ -1,10 +1,13 @@
|
|||||||
<link href="popup.css" rel="stylesheet" type="text/css" />
|
<link href="popup.css" rel="stylesheet" type="text/css" />
|
||||||
<script type="module" src="popup-func.js"></script>
|
<script src="popup-func.js"></script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div>
|
<div>
|
||||||
<div class="title">redirect</div>
|
<div class="title">Redirect Extention</div>
|
||||||
<button id="newButton">New</button><button id="searchButton">Search</button>
|
<button id="newButton">New</button>
|
||||||
<p id="p1link">[click new to generate a link]</p>
|
<input id="output-shortUrl" type="text" disabled>
|
||||||
|
<button id="copyShortUrl-btn">Copy ShortUrl</button> <button id="openShlinkApp-btn">Open App</button>
|
||||||
|
<img id="p1qr-code" src="">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script src="config.js"></script>
|
||||||
|
<script src="popup.js"></script>
|
36
popup.js
Normal file
36
popup.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
var shlinkAppBtnRdUrl = `${config.shlinkAppUrl}`;
|
||||||
|
|
||||||
|
const searchButton = document.getElementById('searchButton');
|
||||||
|
if (searchButton) {
|
||||||
|
searchButton.addEventListener('click', () => {
|
||||||
|
searchRedirect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const newButton = document.getElementById('newButton');
|
||||||
|
if (newButton) {
|
||||||
|
newButton.addEventListener('click', () => {
|
||||||
|
newRedirect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const copyShortUrlBtn = document.getElementById('copyShortUrl-btn');
|
||||||
|
if (copyShortUrlBtn) {
|
||||||
|
copyShortUrlBtn.addEventListener('click', () => {
|
||||||
|
copyShortUrl();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const openShlinkAppBtn = document.getElementById('openShlinkApp-btn');
|
||||||
|
if (openShlinkAppBtn) {
|
||||||
|
copyShortUrlBtn.addEventListener('click', () => {
|
||||||
|
chrome.tabs.create({url:shlinkAppBtnRdUrl});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyShortUrl () {
|
||||||
|
var shortUrlOut = document.getElementById("output-shortUrl");
|
||||||
|
shortUrlOut.select();
|
||||||
|
shortUrlOut.setSelectionRange(0, 99999);
|
||||||
|
navigator.clipboard.writeText(shortUrlOut.value);
|
||||||
|
}
|
Reference in New Issue
Block a user