Skip to content

Commit

Permalink
New feature : update radar from Apple to OpenRadar
Browse files Browse the repository at this point in the history
  • Loading branch information
gcamp committed Jan 24, 2012
1 parent 9e6a0e6 commit d01b695
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 24 deletions.
18 changes: 9 additions & 9 deletions OpenRadarHelper.safariextension/DuplicateRadar.js
Expand Up @@ -19,15 +19,6 @@ function saveDuplicateContent() {
window.open('https://bugreport.apple.com/', "new tab");
}

function addDuplicateButton() {
var button = document.createElement('input');
button.setAttribute('type','button');
button.setAttribute("value", "Duplicate this radar on bugreport.apple.com");
button.setAttribute("style", "position: relative; top: -3px; left: 10px;")
button.onclick = saveDuplicateContent;
document.getElementsByTagName('h3')[0].appendChild(button);
}

function clearDuplicateContent() {
//Clear the data after submission
safari.self.tab.dispatchMessage("probDescID", null);
Expand All @@ -37,4 +28,13 @@ function clearDuplicateContent() {
safari.self.tab.dispatchMessage("classList", null);
safari.self.tab.dispatchMessage("reproducibleNewProb", null);
safari.self.tab.dispatchMessage("wantsDuplicateRadar", null);
}

function addDuplicateButton() {
var button = document.createElement('input');
button.setAttribute('type','button');
button.setAttribute("value", "Duplicate this radar on bugreport.apple.com");
button.setAttribute("style", "position: relative; top: -3px; left: 10px;")
button.onclick = saveDuplicateContent;
document.getElementsByTagName('h3')[0].appendChild(button);
}
5 changes: 5 additions & 0 deletions OpenRadarHelper.safariextension/GlobalPage.html
Expand Up @@ -15,6 +15,11 @@
var returnedValue = [messageEvent.message, value];
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("openRadar", returnedValue);
}
else if (messageEvent.name == "getUpdateValue") {
var value = localStorage.getItem(messageEvent.message);
var returnedValue = [messageEvent.message, value];
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("update", returnedValue);
}
else if (messageEvent.name == "getSettingValue") {
var settingValue = safari.extension.settings.getItem(messageEvent.message);
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage(messageEvent.message, settingValue);
Expand Down
8 changes: 8 additions & 0 deletions OpenRadarHelper.safariextension/Info.plist
Expand Up @@ -31,6 +31,7 @@
<array>
<string>DuplicateRadar.js</string>
<string>SendToOpenRadar.js</string>
<string>UpdateFromApple.js</string>
<string>Main.js</string>
</array>
</dict>
Expand All @@ -48,12 +49,19 @@
<string>openradar.appspot.com</string>
<string>bugreport.apple.com</string>
<string>www.openradar.me</string>
<string>openradar.me</string>
<string>www.bugreport.apple.com</string>
<string>www.openradar.appspot.com</string>
</array>
<key>Include Secure Pages</key>
<true/>
<key>Level</key>
<string>Some</string>
</dict>
</dict>
<key>Update Manifest URL</key>
<string>http://gcamp.ca/openradarhelper/update_feed.plist</string>
<key>Website</key>
<string>http://gcamp.ca/openradarhelper/</string>
</dict>
</plist>
38 changes: 24 additions & 14 deletions OpenRadarHelper.safariextension/Main.js
@@ -1,18 +1,5 @@
var originalAction;

function sendToOpenRadar() {
saveRadarContent();

if (originalAction !== null) originalAction(); //Run the original action
}

function overwriteSubmitButton() {
var sendButton = document.getElementsByName("Save")[0];

originalAction = sendButton.onclick; //Save the action and overwrite the submit button
sendButton.onclick = sendToOpenRadar;
}

function fillDuplicateContent() {
originalAction();

Expand All @@ -35,6 +22,11 @@ function getMessage(msgEvent) { //The GlobalPage.html returned
}
else overwriteSubmitButton();
}
else if (msgEvent.message[0] == "wantsUpdateRadar") {
if (msgEvent.message[1] == "yes") {
lookForRadarToUpdate();
}
}
else if (msgEvent.message[1] != "null") {
document.getElementsByName(msgEvent.message[0])[0].value = msgEvent.message[1];
}
Expand All @@ -52,11 +44,29 @@ function getMessage(msgEvent) { //The GlobalPage.html returned
}
else document.getElementById(msgEvent.message[0]).value = msgEvent.message[1];
}
else if (msgEvent.name == "update") {
var allElements = document.getElementsByTagName("a");
var aElement;

for (aElement in allElements) {
var ref = allElements[aElement].getAttribute("href");
if (ref.indexOf("/radar?id=") === 0) {
var radarNumber = msgEvent.message[1];
if (allElements[aElement].innerHTML.indexOf(radarNumber) != -1 || radarNumber.indexOf(allElements[aElement].innerHTML) != -1) {
window.open('http://www.openradar.me/myradars/edit?id=' + ref.substring(10, ref.length), "new tab");
break;
}
}
}
}
}

safari.self.addEventListener("message", getMessage, false);

if (document.URL == "http://openradar.appspot.com/myradars/add" || document.URL == "http://www.openradar.me/myradars/add") fillContent(); //In OpenRadar bug reporter
else if (document.URL == "http://openradar.appspot.com/myradars" || document.URL == "http://www.openradar.me/myradars") safari.self.tab.dispatchMessage("getOpenRadarValue", "wantsUpdateRadar"); //In OpenRadar bug reporter
else if (document.URL.indexOf("http://openradar.appspot.com/myradars/edit?id=") != -1 || document.URL.indexOf("http://www.openradar.me/myradars/edit?id=") != -1) fillUpdatedContent();
else if (document.URL.indexOf("http://openradar.appspot.com") != -1 || document.URL.indexOf("http://www.openradar.me") != -1) addDuplicateButton(); //In OpenRadar, in description page
else if (document.title.indexOf("New Problem") != -1) safari.self.tab.dispatchMessage("getOpenRadarValue", "wantsDuplicateRadar"); //In Apple bug reporter, in "New Problem" page.
else if (document.title.indexOf("Home") != -1) safari.self.tab.dispatchMessage("getOpenRadarValue", "wantsOpenRadar"); //In Apple bug reporter, in the submission confirmation.
else if (document.title.indexOf("Home") != -1) safari.self.tab.dispatchMessage("getOpenRadarValue", "wantsOpenRadar"); //In Apple bug reporter, in the submission confirmation.
else if (document.title.indexOf("Apple Bug Reporter - ") != -1) addUpdateButton(); //In Apple bug reporter, looking at a existing bug report
21 changes: 20 additions & 1 deletion OpenRadarHelper.safariextension/SendToOpenRadar.js
@@ -1,3 +1,11 @@
var originalAction;

function sendToOpenRadar() {
saveRadarContent();

if (originalAction !== null) originalAction(); //Run the original action
}

function saveRadarContent() {
//Save the radar content in the localStorage
//We need to send message to GlobalPage.html because injected script (this js) store use the site local storage, not the extension one.
Expand All @@ -20,14 +28,25 @@ function clearRadarContent() {
safari.self.tab.dispatchMessage("reproducible", null);
safari.self.tab.dispatchMessage("description", null);
safari.self.tab.dispatchMessage("wantsOpenRadar", null);

safari.self.tab.dispatchMessage("status", null);
safari.self.tab.dispatchMessage("updateRadarNumber", null);
safari.self.tab.dispatchMessage("wantsUpdateRadar", null);
}

function saveRadarNumberAndSubmit() {
safari.self.tab.dispatchMessage("number", document.getElementsByTagName("font")[5].textContent);

clearDuplicateContent();

window.open('http://openradar.appspot.com/myradars/add', "new tab");
window.open('http://openradar.me/myradars/add', "new tab");
}

function overwriteSubmitButton() {
var sendButton = document.getElementsByName("Save")[0];

originalAction = sendButton.onclick; //Save the action and overwrite the submit button
sendButton.onclick = sendToOpenRadar;
}

function fillContent () {
Expand Down
35 changes: 35 additions & 0 deletions OpenRadarHelper.safariextension/UpdateFromApple.js
@@ -0,0 +1,35 @@
function saveUpdatedContent() {
safari.self.tab.dispatchMessage("status", document.getElementById("probid1").getElementsByClassName("data01")[1].textContent);
safari.self.tab.dispatchMessage("description", document.getElementById("probDes").value + "\n\n" + document.getElementById("ADCNote").value);

var radarNumer = document.getElementsByTagName("font")[5].textContent
radarNumer = radarNumer.replace(/(\r\n|\n|\r)/gm,""); //Remove new line
radarNumer = radarNumer.replace(/[ \t\r]+/g,""); //Remove white space
safari.self.tab.dispatchMessage("updateRadarNumber", radarNumer);
safari.self.tab.dispatchMessage("wantsUpdateRadar", "yes");

window.open('http://www.openradar.me/myradars', "new tab");
}

function lookForRadarToUpdate() {
safari.self.tab.dispatchMessage("getUpdateValue", "updateRadarNumber");
}

function addUpdateButton() {
var button = document.createElement('input');
button.setAttribute('type','button');
button.setAttribute("value", "Update this radar on OpenRadar");
button.setAttribute("style", "position: relative; top: -6px; left: 20px;")
button.onclick = saveUpdatedContent;

var headerNode = document.getElementsByName('Revert')[0];

headerNode.parentNode.insertBefore(button, headerNode.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling);
}

function fillUpdatedContent() {
safari.self.tab.dispatchMessage("getOpenRadarValue", "status");
safari.self.tab.dispatchMessage("getOpenRadarValue", "description");

//clearRadarContent();
}

0 comments on commit d01b695

Please sign in to comment.