Skip to content

Commit

Permalink
url change popover created feature implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
prayansh committed Dec 27, 2016
1 parent 19bbc2a commit e385596
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 46 deletions.
32 changes: 12 additions & 20 deletions js/eventPage.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {

if(request === 'showPageAction'){
chrome.pageAction.show(sender.tab.id);
}
else {
var http = new XMLHttpRequest();

http.open('GET', request.url, true);
http.send();

http.onload = function () {
sendResponse({prof: request.prof, result: http.responseText});
};
http.onerror = function () {
sendResponse();
};
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request === 'showPageAction') {
chrome.pageAction.show(sender.tab.id);
}
if (request === 'pageLoad') {
alert('pageLoad');
}
else {
return true; // prevents the callback from being called too early on return
}
});

return true; // prevents the callback from being called too early on return
}
});
2 changes: 1 addition & 1 deletion js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function $x(path) {

function xhrRequest(ability) {
var xhr = new XMLHttpRequest();
xhr.open("GET", abilityAPIUrl(abilities[i].code), true);
xhr.open("GET", abilityAPIUrl(ability.code), true);
xhr.onreadystatechange = function (oEvent) {
if (xhr.readyState === 4) {
// If rest call is good
Expand Down
71 changes: 47 additions & 24 deletions js/peek.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,54 @@
/**
* Created by Prayansh on 2016-12-21.
*/
var targetAbility,
abilities = [];

targetAbility = $x("//ul[@class='AbilityList']/li");
targetAbility.forEach(function (element, index) {
var abilityName = element.innerText;
var abilityCode = abilityName.toLowerCase().replace(' ', '-');
var ability = {
name: abilityName,
code: abilityCode,
index: index,
div: element
};
//give element an id for future
element.id = abilityName.charAt(0) + index;

// Setup loading animation for each popover
$('#' + abilityName.charAt(0) + index).each(function () {
var $elem = $(this);
$elem.popover(popoverOptionsAbility($elem, ability));

function smogonHelper() {
// console.log('Creating popups');
var targetAbility,
abilities = [];

targetAbility = $x("//ul[@class='AbilityList']/li");
targetAbility.forEach(function (element, index) {
var abilityName = element.innerText;
var abilityCode = abilityName.toLowerCase().replace(' ', '-');
var ability = {
name: abilityName,
code: abilityCode,
index: index,
div: element
};
//give element an id for future
element.id = abilityName.charAt(0) + index;

// Setup loading animation for each popover
$('#' + abilityName.charAt(0) + index).each(function () {
var $elem = $(this);
$elem.popover(popoverOptionsAbility($elem, ability));
});

abilities.push(ability);
});

abilities.push(ability);
for (var i = 0; i < abilities.length; i++) {
bindPopupsToAbility(abilities[i]);
}
}

var tBody = $x("//main[@data-reactid='.0.1']");
var tHead = $x("//h1[@data-reactid='.0.1.1.1']");

var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
smogonHelper();
// console.log('something changed');
});
});

for (var i = 0; i < abilities.length; i++) {
bindPopupsToAbility(abilities[i]);
}
// configuration of the observer:
var config = {attributes: true, childList: true, characterData: true};

// pass in the target node, as well as the observer options
observer.observe(tBody[0], config);
observer.observe(tHead[0], config);

smogonHelper();
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Smogon-Helper",
"version": "0.1",
"version": "0.3.6",
"manifest_version": 2,
"author": "Prayansh Srivastava, Mingyu Gao",
"description": "Smogon popups for abilities/moves/items",
Expand Down

0 comments on commit e385596

Please sign in to comment.