2
任何人都可以幫我把我的三個片段放到一個可用的腳本中。下面Jquery/JavaScript - 獲取活動URL,拆分
1) Get active window URL
2) Strip URL for ID only
3) Concatenate API request to include ID from URL
返回我的當前窗口的URL。
chrome.tabs.query({active: true, currentWindow: true},
function(tabs) {
var tabURL = tabs[0].url;
console.log(tabURL);
});
例.... https://myapi.com/users/PLLFFR6
function test() {
var urlID = tabURL.split("/");
urlID = urlID[urlID.length-1];
}
此分裂下來https://myapi.com/users/PLLFFR6並且僅返回 「PLLFFR6」
var authorizationToken = "xxxxxxxxxxxxx";
function myapiRequest(endpoint, options) {
$.ajax($.extend({}, {
type: 'GET',
dataType: "json",
success: function(data) {
$('.Name').html(data.user.name);
$('.Email').html(data.user.email);
$('.Address').html(data.user.teams[0].name);
},
url: "https://api.myapi.com/" + endpoint,
headers: {
"Authorization": "Token token=" + authorizationToken,
"Accept": "application/vnd.myapi+json;version=2"
}
},
options));
}
myapiRequest('/users/' + urlID + '?include%5B%5D=contact_methods&include%5B%5D=teams');
基於此示例myapiRequest應該=
**/users/PLLFFR6?include%5B%5D=contact_methods&include%5B%5D=teams**
像老闆一樣!謝謝 –