Last active
May 6, 2023 00:26
-
-
Save lmccart/33f75e740bc9482f8092 to your computer and use it in GitHub Desktop.
browser extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//////////////////////////////////////////////////////////////////// | |
//// BROWSER ACTION / POPUP | |
{ | |
"manifest_version": 2, | |
"name": "One-click Weather", | |
"description": "This extension demonstrates a 'browser action' with weather.", | |
"version": "1.0", | |
"browser_action": { | |
"default_icon": "icon.png", | |
"default_popup": "popup.html" | |
} | |
} | |
<!doctype html> | |
<html> | |
<head> | |
<title>Getting Started Extension's Popup</title> | |
<style> | |
body { | |
min-width: 357px; | |
overflow-x: hidden; | |
} | |
img { | |
margin: 5px; | |
border: 2px solid black; | |
vertical-align: middle; | |
width: 75px; | |
height: 75px; | |
} | |
</style> | |
<!-- | |
- JavaScript and HTML must be in separate files: see our Content Security | |
- Policy documentation[1] for details and explanation. | |
- | |
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html | |
--> | |
<script src="jquery.js"></script> | |
<script src="popup.js"></script> | |
</head> | |
<body> | |
<div id='weather'></div> | |
</body> | |
</html> | |
function loadWeather() { | |
$.getJSON("http://api.openweathermap.org/data/2.5/weather?id=5128581&units=imperial", function(data) { | |
console.log(data); | |
$('#weather').html("Temperature is: " + data.main.temp ); | |
}); | |
} | |
$(document).ready(function() { | |
loadWeather(); | |
}); | |
//// ALCHEMY | |
function loadSentiment(url) { | |
var params = { | |
url: encodeURI(url), | |
apikey: '8db419e40f6edb29532e48b14b9e6223d7052880', | |
outputMode: 'json' | |
} | |
var url = 'http://access.alchemyapi.com/calls/url/URLGetTextSentiment'; | |
$.getJSON(url, params, function(data) { | |
console.log(data); | |
$('#sentiment').html(data.docSentiment.type+': '+data.docSentiment.score); | |
}); | |
} | |
function getUrl(cb) { | |
var queryInfo = { | |
active: true, | |
currentWindow: true | |
}; | |
chrome.tabs.query(queryInfo, function(tabs) { | |
// chrome.tabs.query invokes the callback with a list of tabs that match the | |
// query. When the popup is opened, there is certainly a window and at least | |
// one tab, so we can safely assume that |tabs| is a non-empty array. | |
// A window can only have one active tab at a time, so the array consists of | |
// exactly one tab. | |
var tab = tabs[0]; | |
// A tab is a plain object that provides information about the tab. | |
// See https://developer.chrome.com/extensions/tabs#type-Tab | |
var url = tab.url; | |
console.log(tab); | |
cb(url); | |
}); | |
} | |
$(document).ready(function() { | |
getUrl(loadSentiment) | |
}); | |
//// BROWSER ACTION / POPUP : Flickr | |
//// BROWSER ACTION / POPUP: Google | |
//////////////////////////////////////////////////////////////////// | |
//// CONTENT SCRIPT | |
{ | |
"manifest_version": 2, | |
"name": "Sentiment Add", | |
"description": "This extension demonstrates a content script with AlchemyAPI.", | |
"version": "1.0", | |
"permissions": [ | |
"activeTab" | |
], | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"<all_urls>" | |
], | |
"js": [ | |
"jquery.js", | |
"content_script.js" | |
], | |
"css": [ | |
"style.css" | |
] | |
}] | |
} | |
function loadSentiment() { | |
var url = window.location.href; | |
console.log(url); | |
var params = { | |
url: encodeURI(url), | |
apikey: '8db419e40f6edb29532e48b14b9e6223d7052880', | |
outputMode: 'json' | |
} | |
var url = 'http://access.alchemyapi.com/calls/url/URLGetTextSentiment'; | |
$.getJSON(url, params, function(data) { | |
console.log(data); | |
$('body').append('<div id="sentiment">'+data.docSentiment.type+': '+data.docSentiment.score+'</div>'); | |
}); | |
} | |
$(document).ready(function() { | |
loadSentiment(); | |
}); | |
//////////////////////////////////////////////////////////////////// | |
//// USING MEDIA LOADED | |
{ | |
"name": "Basic Cursor", | |
"manifest_version": 2, | |
"description": "Makes the cursor much cooler.", | |
"version": "1.0", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"<all_urls>" | |
], | |
"js": [ | |
"scripts/jquery.js", | |
"scripts/content_script.js" | |
] | |
} | |
], | |
"web_accessible_resources": [ | |
"glitter_cursor.gif" | |
] | |
} | |
$("document").ready(function(){ | |
//change cursor | |
$("body").css("cursor", "url('"+chrome.extension.getURL('glitter_cursor.gif')+"'), default"); | |
}); | |
//////////////////////////////////////////////////////////////////// | |
//// BASIC REPLACE | |
{ | |
"name": "Basic replace", | |
"version": "1.0", | |
"manifest_version": 2, | |
"description": "Basic replace", | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"http://www.nytimes.com/*", | |
"http://processing.org/*" | |
], | |
"js": [ | |
"scripts/jquery.js", | |
"scripts/content_script.js" | |
] | |
} | |
], | |
"web_accessible_resources": [ | |
"data/new_lines.txt" | |
] | |
} | |
//------------------DOC READY-------------------// | |
var new_lines = []; | |
$("document").ready(function(){ | |
// load new sentences from text file | |
new_lines = loadStrings("data/new_lines.txt"); | |
changeText(); | |
}); | |
function changeText() { | |
$('a, p').each(function(){ | |
$(this).html(getRandom(new_lines)) | |
//$(this).hide(); | |
}); | |
} | |
//seperates .txt into arrays based on line returns | |
function loadStrings(file) { | |
var result; | |
$.ajax({ | |
type: "GET", | |
url: chrome.extension.getURL(file), | |
async: false, | |
success: function(data){ | |
result = data; | |
} | |
}); | |
return result.split("\n"); | |
} | |
//returns random value in array | |
function getRandom(array){ | |
var index = Math.floor(Math.random()*array.length); | |
var value = array[index]; | |
return value; | |
} | |
//returns true if string contains searched character | |
function contains(string, searchChar){ | |
if(string.indexOf(searchChar) != -1) return true; | |
else return false; | |
} | |
//////////////////////////////////////////////////////////////////// | |
//// GMAIL EMO LABOR | |
//////////////////////////////////////////////////////////////////// | |
//// TTS | |
$(document).ready(function() { | |
chrome.tts.speak('testing testing', {gender: 'female'}); | |
}); | |
//////////////////////////////////////////////////////////////////// | |
//// SPEECH SYNTHESIS | |
$("document").ready(function(){ | |
console.log('hi') | |
var tweets = $('.tweet-text'); | |
var s = $(tweets[0]).text(); | |
console.log(s); | |
var msg = new SpeechSynthesisUtterance(s); | |
window.speechSynthesis.speak(msg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment