1
我做了一個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;
}
如果您需要任何幫助,歡迎隨時加我在Skype:zachripper – Zachrip
真棒非常感謝你Zachrip。我可能會很快與你聯繫! –
@Zachrip我使用一個mac,所以我的朋友,所以通過我的理解豐富的通知不工作在Mac?只有窗戶和chromeOS?我必須改用Chrome桌面通知和後臺頁面嗎? –