我正在尝试构建一个谷歌扩展程序,从名称,教育,技能等CLI配置文件中获取数据。我有三个文件popup.js popup.html和manifest.json。我的问题是在chrome的javascript控制台中运行我的js代码时,它工作得很好但是当把它放在我的popup.js文件中时它似乎不起作用。任何帮助或指导将非常感谢。 这是popup.js
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('checkPage');
checkPageButton.addEventListener('click', function() {
chrome.tabs.query({active:true,currentWindow:true}, function(tab) {
//name
var name=$("#name").text();
alert (name);
//current-position
var current-positionn=$("#headline").text();
alert(current-position);
//phone number
var phone=$("#phone-view").text();
alert (phone);
//email
var address=$("#email").text();
alert (address);
//compétences
var sk=$('span.endorse-item-name-text').text() ; alert(sk);
//expériences
var exp=$('span.new-miniprofile-container').text() ; alert(exp);
});
}, false);
}, false);
popup.html
<html>
<head>
<title>Linkedin web scrapper</title>
<script src="popup.js"></script>
</head>
<body>
<h1>Linkedin web scrapper</h1>
<button id="checkPage">Add Profile</button>
</body>
</html>
{
"manifest_version": 2,
"name": "Linkedin web scrapper",
"description": "This extension will fetch a linkedIn profile data",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"homepage_url": "https://www.linkedin.com/",
"permissions": [
"tabs" ,"activeTab", "https://www.linkedin.com/in/*"
]
}
答案 0 :(得分:0)
我通过添加background.js来解决问题,将代码提取数据,然后将数据发送到popup.js:
这就是BACKGROUND.JS
deleteTodoByID
popup.js
var nom=$("#name").text();
var current_position=$("#headline").text();
var phone=$("#phone-view").text();
var link=$("a.view-public-profile").text();
console.log("success");
// send data to server
window.open("http:// fetchinglocalhost:8080? name="+nom+"&position="+current_position+"&phone="+phone+"&link="+link+"");