Last active
December 21, 2015 01:48
-
-
Save jbrooksuk/6229850 to your computer and use it in GitHub Desktop.
AutoIt Forum Minimizer - Tidied up
This file contains 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
/* jshint devel:true */ | |
/** | |
AutoIt Forum Minimizer v1.1.1 by FireFox | |
http://www.autoitscript.com/forum/user/42741-firefox/ | |
**/ | |
(function () { | |
"use strict"; | |
var $j = jQuery.noConflict(); | |
var aSettings = [ | |
'shrf:Shorten the header (reduced logo, search engine into the user navbar).;' + | |
'fhb:Make the headerbar floating.', | |
'rfst:Reduce the forum section title font size.', | |
'hfsd:Hide the forum section description.', | |
'hfsa:Hide the forum section announcement (will be automatically re-showed for any changes).', | |
'hptr:Hide the pinned topics read.', | |
'hfsf:Hide the forum section filterbar.' | |
// 'esrt:Enable smileys in raw text mode.'), | |
]; | |
var dc = { | |
$logo: $j('#logo'), | |
$branding: $j('#branding'), | |
$search: $j('#search'), | |
$search_wrap: $j('#search_wrap'), | |
$main_search: $j('#main_search'), | |
$secondary_navigation: $j('#secondary_navigation'), | |
}; | |
var fInit = true; | |
loadSettings(); | |
loadPopup(); | |
//Strip the doc name on saving | |
var fCtrl = false; | |
var fDocTitleChanged = false; | |
var sDocTitle = ''; | |
$j(document).keydown(function (e) { | |
switch (e.keyCode) { | |
case 17: //Ctrl | |
fCtrl = true; | |
break; | |
case 83: //83: S | |
if (!fCtrl) { | |
break; | |
} | |
sDocTitle = document.title; | |
var iHyphenPos = sDocTitle.lastIndexOf(' - '); | |
iHyphenPos = sDocTitle.lastIndexOf(' - ', iHyphenPos - 1); | |
document.title = sDocTitle.substr(0, iHyphenPos); | |
fDocTitleChanged = true; | |
break; | |
} | |
}).keyup(function (e) { | |
switch (e.keyCode) { | |
case 17: | |
fCtrl = false; | |
break; | |
case 83: | |
if (fDocTitleChanged) { | |
document.title = sDocTitle; | |
fDocTitleChanged = false; | |
} | |
} | |
}); | |
function loadSettings(sToLoad) { | |
var inner = { | |
shrf: function () { | |
var fIsMod = ($j('#admin_bar').length > 0 ? true : false); | |
//logo | |
dc.$logo.css('display', (fIsMod ? 'none' : 'block')); | |
if (!fIsMod) { | |
dc.$logo.find('img').css({ | |
'width': '105px', | |
'height': '36px', | |
'margin-top': '28px' | |
}); | |
} | |
//blue part between the user nav and the global nav | |
dc.$branding.css({ | |
'background': 'none', | |
'margin-top': '-64px' | |
}); | |
//search engine | |
dc.$search.css({ | |
'float': 'left', | |
'margin': (fIsMod ? '5' : '-31') + 'px 0 0 ' + (fIsMod ? '43' : '160') + 'px', | |
'height': '6px' | |
}); | |
dc.$search_wrap.css({ | |
'display': 'inline-block', | |
'min-width': (fIsMod ? '396' : '483') + 'px' | |
}); | |
dc.$main_search.css('width', (fIsMod ? '313' : '400') + 'px'); | |
//line break before the topic's title | |
dc.$secondary_navigation.next().hide(); | |
//forum section/topic page nav | |
var oTopicControls = $j('div.topic_controls'); | |
if (oTopicControls.length > 0 && $j('div.topic.hfeed').length > 0) { //topic | |
var iTagsLen = $j('a.ipsTag').length; | |
if ($j(oTopicControls).find('div.pagination.clearfix').length > 0) { | |
oTopicControls.eq(0).css('margin-top', (iTagsLen > 0 ? '-12' : '-14') + 'px'); | |
if (iTagsLen === 0) { | |
$j('ul.ipsList_inline.left.pages').css('margin-left', '6px'); | |
} | |
} else { | |
oTopicControls.eq(0).css('margin-top', (iTagsLen > 0 ? '-46' : '-22') + 'px'); | |
} | |
} | |
}, | |
fhb: function () { | |
//floating headerbar | |
$j('#ipbwrapper').prepend('<div id="aufm_headerbar"></div>'); | |
$j('#header_bar,#branding').appendTo('#aufm_headerbar'); | |
$j(window).scroll(function () { | |
if ($j(document).scrollTop() > 0) { | |
$j('#aufm_headerbar').addClass('aufm_floatingtop'); | |
} else { | |
$j('#aufm_headerbar').removeClass('aufm_floatingtop'); | |
} | |
}); | |
$j('body').bind('DOMNodeInserted', function (e) { | |
if ($j(e.target).attr('id') === 'ajax_loading') { | |
$j(e.target).css({ | |
'left': '58px', | |
'top': '37px' | |
}); | |
$j('body').unbind('DOMNodeInserted'); | |
} | |
}); | |
dc.$branding.css('background', 'none'); //fix bg issue (caused by adding style) | |
}, | |
rfst: function () { | |
//forum section title | |
$j('h1.ipsType_pagetitle').eq(0).css('font-size', '20px'); | |
}, | |
hfsd: function () { | |
//forum section description | |
$j('div.ipsType_pagedesc').eq(0).hide(); | |
}, | |
hfsa: function () { | |
//forum section announcement | |
var oAnnounTable = $j('#announcements'); | |
if (oAnnounTable.length > 0) { | |
var sAl = localStorage.getItem('aufms_at'); | |
var sCurrentAl = oAnnounTable.find('h4 a').html(); | |
if (sAl !== null && sAl !== sCurrentAl) { | |
//re-show the announcement (different one) | |
var aDesc = 0; | |
var aSubDesc = 0; | |
for (var i = 0; i < aSettings.length; i++) { | |
aDesc = aSettings[i].split(';'); | |
for (var i2 = 0; i2 < aDesc.length; i2++) { | |
aSubDesc = aDesc[i2].split(':'); | |
if (aSubDesc[0] !== 'hfsa') { | |
continue; | |
} | |
aSubDesc[2] = 'false'; | |
aDesc[i2] = aSubDesc.join(':'); | |
} | |
aSettings[i] = aDesc.join(';'); | |
} | |
} else { | |
oAnnounTable.next().hide(); //below line break | |
oAnnounTable.hide(); | |
} | |
if (sAl === null || sAl !== sCurrentAl) { | |
localStorage.setItem('aufms_at', sCurrentAl); | |
} | |
} | |
}, | |
hptr: function () { | |
//forum section pinned topics | |
$j('tr.__topic').each(function () { | |
var oBadge = $j(this).find('span.ipsBadge.ipsBadge_green'); | |
if (oBadge.length === 0 || oBadge.html() !== 'Pinned') { | |
return false; | |
} | |
if (!$j(this).hasClass('unread')) { | |
$j(this).hide(); | |
} | |
}); | |
}, | |
hfsf: function () { | |
//forum section filterbar | |
var oFilterBar = $j('div.ipsFilterbar.maintitle'); | |
if (oFilterBar.length > 0) { | |
oFilterBar.hide(); | |
} | |
} //, | |
// esrt: function() { | |
//raw text mode | |
// cke_6 : toggle | |
// cke_14 : smiley | |
// } | |
}; | |
if (sToLoad !== undefined) { | |
inner[sToLoad](); | |
return; | |
} | |
if (localStorage.getItem('aufm_set') !== 'true') { | |
fInit = false; | |
$j('#aufmsLaunch') | |
.addClass('lightanim') | |
.parents('li').eq(0).css('background-color', '#7ba60d'); | |
} | |
if (localStorage.getItem('aufm_author') !== 'true') { | |
//surprise for the user | |
$j('span.usermvp:contains("FireFox")') | |
.addClass('lightanim big') | |
.mouseover(function () { | |
alert('Thank you for installing the AutoIt Forum Minimizer !' + "\n" + 'You rock :)'); | |
$j(this).unbind().removeClass('lightanim big'); | |
localStorage.setItem('aufm_author', true); | |
}); | |
} | |
var fIsWriting = false; | |
var iDOMChangedCount = 0; | |
$j('#ips_fastReplyForm,#postingform').bind('DOMNodeInserted', function (e) { | |
if ($j(e.target).is('iframe')) { | |
// $j('#ips_fastReplyForm').unbind('DOMNodeInserted'); | |
$j(e.target).contents().find('body').bind('DOMNodeInserted', function () { | |
iDOMChangedCount += 1; | |
if ($j(this).html() === '<p><br></p>') { | |
iDOMChangedCount = 0; | |
$j(window).unbind('beforeunload'); | |
fIsWriting = false; | |
} | |
if (iDOMChangedCount > 4) { | |
if (!fIsWriting) { | |
fIsWriting = true; | |
$j(window).bind('beforeunload', function () { | |
return 'You haven\'t finished your post yet!'; | |
}); | |
} | |
} | |
}); | |
} else if ($j(e.target).is('textarea')) { | |
$j(e.target).bind('keyup', function () { | |
if ($j(this).val()) { | |
if (!fIsWriting) { | |
fIsWriting = true; | |
$j(window).bind('beforeunload', function () { | |
return 'You haven\'t finished your post yet!'; | |
}); | |
} | |
} else { | |
fIsWriting = false; | |
$j(window).unbind('beforeunload'); | |
} | |
}); | |
} | |
}); | |
$j('.input_submit,input[name="submit"]').click(function () { | |
$j(window).unbind('beforeunload'); | |
}); | |
var aDesc = 0; | |
var aSubDesc = 0; | |
for (var i = 0; i < aSettings.length; i++) { | |
aDesc = aSettings[i].split(';'); | |
for (var i2 = 0; i2 < aDesc.length; i2++) { | |
aSubDesc = aDesc[i2].split(':'); | |
if (localStorage.getItem('aufm_' + aSubDesc[0]) !== 'true') { | |
aSubDesc[2] = 'false'; | |
} else { | |
aSubDesc[2] = 'true'; | |
inner[aSubDesc[0]](); | |
} | |
aDesc[i2] = aSubDesc.join(':'); | |
} | |
aSettings[i] = aDesc.join(';'); | |
} | |
} | |
function unloadSettings(sToUnload) { | |
var inner = { | |
shrf: function () { | |
//reduced header | |
//logo | |
dc.$logo.css('display', ''); | |
$j('#logo img').css({ | |
'width': '', | |
'height': '', | |
'margin-top': '' | |
}); | |
//blue part between the user nav and the global nav | |
dc.$branding.css({ | |
'background': '', | |
'margin-top': '' | |
}); | |
//search engine | |
dc.$search.css({ | |
'float': '', | |
'margin': '', | |
'height': '' | |
}); | |
dc.$search_wrap.css({ | |
'display': '', | |
'min-width': '' | |
}); | |
dc.$main_search.css('width', ''); | |
//line break before the topic's title | |
dc.$secondary_navigation.next().show(); | |
//forum section/topic page nav | |
var oTopicControls = $j('div.topic_controls'); | |
if (oTopicControls.length > 0 && $j('div.topic.hfeed').length > 0) { //topic | |
var iTagsLen = $j('a.ipsTag').length; | |
if ($j(oTopicControls).find('div.pagination.clearfix').length > 0) { | |
oTopicControls.eq(0).css('margin-top', ''); | |
if (iTagsLen === 0) { | |
$j('ul.ipsList_inline.left.pages').css('margin-left', ''); | |
} | |
} else { | |
oTopicControls.eq(0).css('margin-top', ''); | |
} | |
} | |
}, | |
fhb: function () { | |
//floating headerbar | |
$j('#header_bar,#branding').prependTo('#ipbwrapper'); | |
$j('#aufm_headerbar').remove(); | |
$j(window).unbind('scroll'); | |
$j('body').unbind('DOMNodeInserted'); | |
}, | |
rfst: function () { | |
//forum section title | |
$j('h1.ipsType_pagetitle').eq(0).css('font-size', ''); | |
}, | |
hfsd: function () { | |
//forum section description | |
$j('div.ipsType_pagedesc').eq(0).show(); | |
}, | |
hfsa: function () { | |
//forum section announcement | |
var oAnnounTable = $j('#announcements'); | |
if (oAnnounTable.length > 0) { | |
oAnnounTable.next().show(); //below line break | |
oAnnounTable.show(); | |
} | |
}, | |
hptr: function () { | |
//forum section pinned topics | |
$j('tr.__topic').each(function () { | |
var oBadge = $j(this).find('span.ipsBadge.ipsBadge_green'); | |
if (oBadge.length === 0 || oBadge.html() !== 'Pinned') { | |
return false; | |
} | |
if (!$j(this).hasClass('unread')) { | |
$j(this).show(); | |
} | |
}); | |
}, | |
hfsf: function () { | |
//forum section filterbar | |
var oFilterBar = $j('div.ipsFilterbar.maintitle'); | |
if (oFilterBar.length > 0) { | |
oFilterBar.show(); | |
} | |
} | |
}; | |
inner[sToUnload](); | |
return; | |
} | |
function loadPopup() { | |
var sPopupHTML = '<div id="aufms_popup" class="popupWrapper" style="z-index: 10001; top: 29px; position: fixed;">'; | |
sPopupHTML += '<div class="popupInner" style="width: 600px;"><h3>AutoIt Forum Minimizer - Settings</h3>'; | |
sPopupHTML += '<div class="fixed_inner ipsBox" style="height: 223px; overflow: auto;">'; | |
var aDesc = 0; | |
var aSubDesc = 0; | |
for (var i = 0; i < aSettings.length; i++) { | |
aDesc = aSettings[i].split(';'); | |
for (var i2 = 0; i2 < aDesc.length; i2++) { | |
aSubDesc = aDesc[i2].split(':'); | |
sPopupHTML += '<p' + (i2 > 0 ? ' class="tab"' : '') + '><input type="checkbox" id="aufms_cb' + aSubDesc[0] + '" /><label for="aufms_cb' + aSubDesc[0] + '">' + aSubDesc[1] + '</label></p>'; | |
} | |
} | |
sPopupHTML += '<a href="#" id="aufms_apply" class="ipsButton" title="Apply changes">Apply</a>'; | |
sPopupHTML += '</div>'; | |
sPopupHTML += '</div>'; | |
sPopupHTML += '<div id="aufms_popupclose" class="popupClose clickable">'; | |
sPopupHTML += '<img src="http://aut1.autoit-cdn.com/forum/public/style_images/master/close_popup.png" alt="x">'; | |
sPopupHTML += '</div>'; | |
sPopupHTML += '</div>'; | |
$j('body').append(sPopupHTML); | |
$j('#aufms_popup input[type="checkbox"]').change(function () { | |
var oP = $j(this).parents('p').eq(0); | |
if ($j(oP).hasClass('tab')) { | |
return; | |
} | |
for (;;) { | |
oP = $j(oP).next('p'); | |
if (!$j(oP).hasClass('tab')) { | |
break; | |
} | |
if ($j(this).is(':checked')) { | |
$j(oP).find('input') | |
.removeAttr('disabled'); | |
} else { | |
$j(oP).find('input') | |
.attr('disabled', 'disabled') | |
.removeAttr('checked'); | |
} | |
} | |
}); | |
function ibpfs_open() { | |
if (!fInit) { | |
localStorage.setItem('aufm_set', true); | |
$j('#aufmsLaunch') | |
.removeClass('lightanim') | |
.parents('li').eq(0).css('background-color', ''); | |
} | |
var fParentChecked = false; | |
for (i = 0; i < aSettings.length; i++) { | |
aDesc = aSettings[i].split(';'); | |
for (var i2 = 0; i2 < aDesc.length; i2++) { | |
aSubDesc = aDesc[i2].split(':'); | |
if (i2 === 0 && aSubDesc[2] === 'true') { | |
fParentChecked = true; | |
} else if (i2 > 0 && !fParentChecked) { | |
$j('#aufms_cb' + aSubDesc[0]).attr('disabled', 'disabled'); | |
} | |
if (aSubDesc[2] !== 'true') { | |
continue; | |
} | |
$j('#aufms_cb' + aSubDesc[0]).attr('checked', 'checked'); | |
} | |
fParentChecked = false; | |
} | |
var oPopup = $j('#aufms_popup'); | |
oPopup.css('left', $j(window).width() / 2 - oPopup.width() / 2 + 'px'); | |
oPopup.fadeIn('fast'); | |
} | |
$j('#aufms_popupclose').click(function () { | |
ibpfs_close(); | |
}); | |
function ibpfs_close() { | |
$j('#aufms_popup').fadeOut('fast'); | |
} | |
$j('#aufms_apply').click(function () { | |
var fChecked = false; | |
for (var i = 0; i < aSettings.length; i++) { | |
aDesc = aSettings[i].split(';'); | |
for (var i2 = 0; i2 < aDesc.length; i2++) { | |
aSubDesc = aDesc[i2].split(':'); | |
fChecked = $j('#aufms_cb' + aSubDesc[0]).is(':checked'); | |
if (fChecked && aSubDesc[2] !== 'true') { | |
loadSettings(aSubDesc[0]); | |
} else if (!fChecked && aSubDesc[2] === 'true') { | |
if (aSubDesc[0] === 'hfsa') { | |
localStorage.removeItem('aufms_at'); | |
} | |
unloadSettings(aSubDesc[0]); | |
} | |
localStorage.setItem('aufm_' + aSubDesc[0], fChecked); | |
aSubDesc[2] = fChecked; | |
aDesc[i2] = aSubDesc.join(':'); | |
} | |
aSettings[i] = aDesc.join(';'); | |
} | |
ibpfs_close(); | |
return false; | |
}); | |
//launch button | |
var launchButton = ''; | |
launchButton += '<li class="right">'; | |
launchButton += '<a href="#" id="aufmsLaunch" title="Open AutoIt Forum Minimizer Settings">'; | |
launchButton += '<span> </span>'; | |
launchButton += '</a>'; | |
launchButton += '</li>'; | |
$j('#community_app_menu').prepend(launchButton); | |
$j('#aufmsLaunch').click(function () { | |
ibpfs_open(); | |
return false; | |
}).hover(function () { | |
$j(this).find('span').css('opacity', 1); | |
}).mouseleave(function () { | |
$j(this).find('span').css('opacity', ''); | |
}); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment