v1
This commit is contained in:
		
							parent
							
								
									a789b77b5f
								
							
						
					
					
						commit
						a48e1f9b40
					
				
							
								
								
									
										0
									
								
								assets/logo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								assets/logo.png
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								background.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								background.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										15
									
								
								manifest.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								manifest.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
			
		||||
{
 | 
			
		||||
    "name": "redirect",
 | 
			
		||||
    "version": "0.1.0",
 | 
			
		||||
    "description": "create a redirect directly",
 | 
			
		||||
    "permissions": ["storage", "tabs"],
 | 
			
		||||
    "background": {
 | 
			
		||||
      "service_worker": "background.js"
 | 
			
		||||
    },
 | 
			
		||||
    "action": {
 | 
			
		||||
      "default_icon": "assets/icon.png",
 | 
			
		||||
      "default_title": "redirect",
 | 
			
		||||
      "default_popup": "popup.html"
 | 
			
		||||
    },
 | 
			
		||||
    "manifest_version": 3
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										48
									
								
								popup-func.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								popup-func.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
			
		||||
const searchButton = document.getElementById('searchButton');
 | 
			
		||||
if (searchButton) {
 | 
			
		||||
    searchButton.addEventListener('click', () => {
 | 
			
		||||
        searchRedirect('test');
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
const newButton = document.getElementById('newButton');
 | 
			
		||||
if (newButton) {
 | 
			
		||||
    newButton.addEventListener('click', () => {
 | 
			
		||||
        newRedirect('test');
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function searchRedirect(host) {
 | 
			
		||||
    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(host) {
 | 
			
		||||
    chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
 | 
			
		||||
        let currentUrl = tabs[0].url;
 | 
			
		||||
        const url = 'https://url.example.com/rest/v3/short-urls';
 | 
			
		||||
        let sendData = {
 | 
			
		||||
            "longUrl": currentUrl,
 | 
			
		||||
            "tags": ["Added by BOTv1"]
 | 
			
		||||
        };
 | 
			
		||||
        const request = new XMLHttpRequest();
 | 
			
		||||
        request.open('POST', url);
 | 
			
		||||
        request.setRequestHeader('accept', 'application/json');
 | 
			
		||||
        request.setRequestHeader('X-Api-Key', 'apikeyhere');
 | 
			
		||||
        request.setRequestHeader('Content-type', 'application/json');
 | 
			
		||||
        request.send(JSON.stringify(sendData));
 | 
			
		||||
        request.onload = (e) => {
 | 
			
		||||
            var responseData = request.response;
 | 
			
		||||
            document.getElementById("p1link").innerHTML = responseData;
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								popup.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								popup.css
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,22 @@
 | 
			
		||||
.container {
 | 
			
		||||
    width: 360px;
 | 
			
		||||
    color: #314d3e;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  .title {
 | 
			
		||||
    font-size: 16px;
 | 
			
		||||
    font-weight: bold;
 | 
			
		||||
    padding: 10px;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  .textbox {
 | 
			
		||||
    width: 100%;
 | 
			
		||||
    font-size: 10px;
 | 
			
		||||
    margin: 0;
 | 
			
		||||
    padding: 0px 2px;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  .textbox:focus {
 | 
			
		||||
    outline: 0;
 | 
			
		||||
    border-color: #66afe9;
 | 
			
		||||
  }
 | 
			
		||||
							
								
								
									
										10
									
								
								popup.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								popup.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
<link href="popup.css" rel="stylesheet" type="text/css" />
 | 
			
		||||
<script type="module" src="popup-func.js"></script>
 | 
			
		||||
 | 
			
		||||
<div class="container">
 | 
			
		||||
  <div>
 | 
			
		||||
    <div class="title">redirect</div>
 | 
			
		||||
    <button id="newButton">New</button><button id="searchButton">Search</button>
 | 
			
		||||
    <p id="p1link">[click new to generate a link]</p>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
		Reference in New Issue
	
	Block a user