rendered paste body// ==UserScript==
// @name Bug Traq
// @description Emails the specified address a copy of the bug report
// @source http://my.opera.com/community/forums/topic.dml?id=217364
// @indentifier http://files.myopera.com/fearphage/userjs/my/bugtraq.js
// @namespace http://my.opera.com/fearphage/info
// @author fearphage
// @include https://bugs.opera.com/wizard/*
// ==/UserScript==
(function() {
var defaultEmail = 'ramunazz@gmail.com' // the email address you would like filled in automatically in all reports
,notifyOnSucess = true // popup an alert after you submit each bug confirming the email was sent
,logToPublicBTS = true // changing this to true will get your bugs logged to http://opera.remcol.ath.cx/bugs/ also
/*
* OPTIONAL parameters
* These settings only apply to those that have logins for http://opera.remcol.ath.cx/bugs/
* If you do not have a login you can still post your bugs to the Public BTS with no problems
*/
var publicBTSUsername = "Ramunas" // if you're posting it to the public BTS and you have an account there, input
your username here
,publicBTSKey = "****"; // the key that is linked to your username, you can find it
on http://opera.remcol.ath.cx/bugs/index.php?action=profile
/*
* DO NOT EDIT BELOW THIS POINT
*/
var list = {
severity: 'Severity: '
,component: 'Component: '
,summary: 'Summary: '
,url: 'URL: '
,version: 'Version: '
,opsys: 'Operating System: '
,platform: 'Platform: '
,build: 'Build: '
,repro: '\nSteps to reproduce:\n\t'
,detail2: '\nExpected results:\n\t'
,detail1: '\nActual Results:\n\t'
,auto: '\nUserAgent, Language, Plugins, Resolution:\n\t'
}, textareas = 'repro|detail2|detail1|auto', cookiePrefix = 'bugtraq:'
,pubBTS = 'http://opera.remcol.ath.cx/bugs/userjs.php?';
document.addEventListener('DOMContentLoaded'
,function() {
var search = location.search, form;
if (form = document.selectSingleNode('//form[@id="bug" or @name="bug"]')) {
form.addEventListener('submit', rememberForm, false);
var mail = form.elements['mail'];
if (mail && defaultEmail) {
mail.value = defaultEmail;
mail.style.backgroundColor = '#ffffcc';
}
}
else if ((bug = search.match(/^\?thanks=(\d+)$/i)) && (document.cookie.match(new RegExp('\\b(' + cookiePrefix + '[a-z]+)=')))) {
if (!(bug = bug[1])) { alert('Failed to find bug number\nEmail NOT sent\nPlease notify fearphage.\n\nhttp://my.opera.com/community/forums/topic.dml?id=217364'); return; }
var msg = getCookie('bulk'), additions = textareas.split('|'), email = getCookie('email'), title = getCookie('summary');
if (email && msg) {
for (var i = 0, name; name = additions[i]; i++)
msg += list[name] + getCookie(name) + '\n';
sendEmail(email, 'bug-' + bug + '@bugs.opera.com', msg, bug, title || null);
if (msg = getCookie('uniqueID')) (new Image()).src = pubBTS + 'mysqlid=' + msg + '&bugid=' + bug;
//cleanup();
}
}
}
,false
);
function rememberForm(e) {
var form = e.target, email = (form.elements['mail'] ? form.elements['mail'].value : (typeof defaultEmail != 'undefined' ? defaultEmail : false));
if (!email) return;
var str = '', btsQuery = [], el, value, replacements = {'&': '%26', '=': '%3D', '\t': '', '\n': '%0A', '%': '%25', '#': '%23', '?': '%3F'}
,htmlize = {'<': '<', '&': '&', '>': '>'};
for (var name in list) {
el = form.elements[name];
if (!el) continue;
value = getValue(el);
if ('auto|mail'.indexOf(name) == -1)
btsQuery.push(name + '=' + escape(value.replace(/\t/g, '')));
if (textareas.indexOf(name) > -1)
setCookie(name, value.replace(/[<&>]/g, function(c) { return htmlize[c]; }));
else {
if (name == 'summary')
setCookie(name, value);
str += list[name] + value + '\n';
}
}
doLogToPublicBTS(btsQuery);
setCookie('bulk', str);
setCookie('email', email);
}
function getValue(element) {
switch (element.tagName) {
case 'INPUT':
case 'TEXTAREA':
return element.value.replace(/(\r\n|\r|\n)/g, '$1\t');
case 'SELECT':
return element[element.selectedIndex].value;
}
}
function doLogToPublicBTS(params) {
if (logToPublicBTS != true) return;
var doc = document, script = doc.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', pubBTS + params.join('&') + '&callback=getFromPublicBTS' + (publicBTSUsername && publicBTSKey ? '&user=' + publicBTSUsername + '&key=' + publicBTSKey : ''));
var parent = doc.selectSingleNode('//head') || doc.body;
parent.appendChild(script);
}
function sendEmail(to, from, str, bug, title) {
if (!to || !str) return;
str = (bug ? 'Bug #: ' + bug + '\n' : '') + str + '\n\n\nsent via userjs (http://files.myopera.com/fearphage/userjs/my/bugtraq.js)';
var img = new Image(), onSuccess = function() { alert('Bug report #' + bug + ' sent to ' + to); };
img.addEventListener('error'
,(function(element) { // enclosure
return function() {
// attempt to overcome an opera bug were ONLOAD fires after ONERROR
element.removeEventListener('load', onSuccess, false);
alert('There was an error submitting your email request');
};
})(img)
,false
);
if (notifyOnSucess)
img.addEventListener('load', onSuccess, false);
img.src = 'http://fearphage.com/imagine.php?to=' + encodeURIComponent(to) +
'&from=' + encodeURIComponent(from || 'noreply@opera.com') +
'&msg=' + encodeURIComponent(str) +
(bug ? '&bug=' + bug : '') +
(title ? '&title=' + encodeURIComponent(title) : '');
}
function setCookie(name, value) {
document.cookie = cookiePrefix + name + '=' + (value ? escape(value) : '') + '; expires=' + new Date(new Date().getTime() + (value ? 60*1000 /*1 minute*/ : -1)).toGMTString();
}
function getCookie(name) {
var regex = new RegExp('\\b' + cookiePrefix + name + '=([^;]+)'), match = document.cookie.match(regex);
return (match ? unescape(match[1].replace(/^\s+|\s+$/g, '')) : '');
}
function cleanup() {
var m = document.cookie.match(new RegExp('\\b(' + cookiePrefix + '[a-z]+)=', 'ig'));
if (!m) return;
for (var i = 1; i < m.length; i++)
setCookie(m[i], false);
}
window.getFromPublicBTS = function(obj) {
var id = obj.mysqlid;
if (typeof id != 'undefined')
setCookie('uniqueID', id);
};
})();
/*
* 122007
- integrated with Remco's BTS
- more robust
* 110407
- bug fix (thanks d.i.z.)
- code optimization and cleanup
* 102007 -
- updated to compensate for wizard change (changed form.name to form.id)
- added bug description to email subject
* 091407 - initial release
*/