我做了一个chrome扩展。它非常简单。这是一系列的恭维,当有人点击扩展并将其打印出来时,我会随机抽出一个。我也使用chromes tts(文本到语音)来大声说出赞美。这很简单,但是.......
我希望它随机给你一个赞美,而没有人点击Chrome扩展程序。这可能吗?我做了一些研究没有成功。继承我的代码:
popup.js:
$(document).ready(function() {
var compliments = ['You are awesome.', 'Looking good.'];
var randomCompliment = Math.floor(Math.random()*compliments.length);
$('#compliment').append('<li>' + compliments[randomCompliment] + '</li>');
chrome.tts.speak(compliments[randomCompliment])
});
的manifest.json:
{
"manifest_version": 2,
"name": "Complimentor",
"description": "This extension gives you a compliment.",
"version": "1.0",
"browser_action": {
"default_icon": {
"19": "icon_19.png",
"38": "icon_38.png"
},
"default_title": "Complimentor",
"default_popup": "popup.html"
},
"permissions": ["tts"]
}
popup.html:
<!doctype html>
<html>
<head>
<script src="jquery.js"></script>
<script src="popup.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="popup">
<div id="highlight"></div>
<ul id="compliment"></ul>
</div>
</body>
</html>
的style.css:
body {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0)), color-stop(100%,rgba(0,0,0,0.1))); /* Chrome,Safari4+ */
}
.popup {
width: 300px;
font: 14px helvetica-neue, helvetica, sans-serif;
color: #666;
position: relative;
text-align: center;
}
#hightlight {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,.3)), color-stop(100%, rgba(255,255,255,0))); /* Chrome,Safari4+ */
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
.popup ul {
list-style: none;
margin: 0;
padding: 0;
}
.popup li {
padding: 3px 0;
}
答案 0 :(得分:3)
目前无法以编程方式打开Chrome扩展程序弹出窗口。但您可以使用桌面通知来显示通知,而在测试版Chrome中,则会有丰富的通知。您可以使用后台脚本随机设置超时,当它超时时,您可以让它创建通知,并播放声音。
参考链接: