Skip to content

Instantly share code, notes, and snippets.

@chaselivingston
Created April 14, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaselivingston/69fa5fada0a4b31b0714 to your computer and use it in GitHub Desktop.
Save chaselivingston/69fa5fada0a4b31b0714 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Store Olark Helper
// @include https://chat.olark.com/*
// ==/UserScript==
var $ = unsafeWindow.jQuery;
// ------------------------------------------------------
// TOP BUTTONS
// ------------------------------------------------------
$( '#chat-container h1' ).css( { 'display' : 'inline' } );
$( '#conflicting-resources' ).css( { 'display' : 'none' } );
// Add link buttons to Store Schedule and Google Calendar
var urls = {
'Schedule': 'https://mc.a8c.com/store/schedule/',
'Calendar': 'https://www.google.com/calendar/',
'MGS': 'https://mc.a8c.com/mgs/'
};
for( var url in urls ) {
$( "header" ).append( '<a href="' + urls[url] + '" data-role="button" class="button" data-inline="true" style="margin-top: -5px; margin-left: 5px;" target="_blank">' + url + '</a>' );
}
// ------------------------------------------------------
// TAGS AND LINKS
// ------------------------------------------------------
// gets conversations container
var target = $( '#conversations' )[0];
// defines observer to track new chats added
var observer = new MutationObserver( function( mutations ) {
mutations.forEach( function ( mutation ) {
var newNodes = mutation.addedNodes;
if( newNodes !== null ) {
var $nodes = $( newNodes );
$nodes.each( function() {
var $node = $( this );
if( $node.hasClass( 'conversation-view' ) ) {
addExtras( $node );
}
});
}
});
});
var config = {
attributes: true,
childList: true,
characterData: true
};
// initiates observer
observer.observe( target, config );
// content related functions related --------------------
function addExtras( chat ) {
var sidePanel = $( chat ).find( '.visitor-info-pane');
var tagList = createTagList( chat );
var NALinks = getNALinks( chat );
// CSS changes to sidebar
$( chat ).find( '.visitor-info-pane').css( { 'padding-top' : '0' } );
$( chat ).find( '.buddy-status-view').css( { 'position' : 'relative', 'float' : 'right', 'width' : '300px' } );
$( chat ).find( '.profile-area').css( { 'left' : '0' } );
// creates extra section on the sidebar
var extras = $( '<div class="extras" style="width: 300px; float: right; clear: right;">' );
$( extras ).append( NALinks );
$( extras ).append( tagList );
$( sidePanel ).append( extras );
}
function getUsername( chat ) {
var usernameHeader = $( chat ).find( '.header-nickname' ).text();
var userName = usernameHeader.split( ' | ' )[0].split( ' ' );
return userName[userName.length - 1];
}
function getNALinks ( chat ) {
var username = getUsername( chat );
var upgradesLink = '<a href="https://wordpress.com/wp-admin/network/wpcom-paid-upgrades.php?action=search&username=' + username + '" class="button" style="margin-top: 10px;" target="_blank">Store Admin</a>';
return upgradesLink;
}
function createTagList( chat ) {
var tags = getTags();
var tagList = $( '<ul>', { style: '-webkit-padding-start: 0; -moz-padding-start: 0; padding-start: 0; font-size: 11px;' } );
tags.forEach( function( tag ) {
$( tagList ).append( getTagLink( chat, tag ) );
});
return tagList;
}
function getTagLink( chat, tagName ) {
var tagLink = $( '<li>', { style: 'cursor: pointer; display: inline-block; background-color: #eee; padding: 5px; margin: 3px; color: #666; border-radius: 5px; border: 1px solid #ccc;' } );
$( tagLink ).text( tagName );
$( tagLink ).click( { inputField: $( chat ).find( '.text-input'), tagName: tagName }, insertTag );
return tagLink;
}
function insertTag( event ) {
var inputField = event.data.inputField;
var currentText = $( inputField ).val();
var tagName = event.data.tagName;
if( currentText === '' ) {
$( inputField ).val( '!tag ' + tagName );
$( this ).css( { 'background-color' : '#fffbdd', 'color' : '#a1a219', 'border' : '1px solid #d8d8bd' } );
} else if( currentText.indexOf( '!tag' ) === 0 ) {
$( inputField ).val( currentText + ' ' + tagName );
$( this ).css( { 'background-color' : '#fffbdd', 'color' : '#a1a219', 'border' : '1px solid #d8d8bd' } );
}
$( inputField ).focus();
}
function getTags() {
return [ '.org', '2fa', 'ads', 'AR', 'calendar', 'cancel', 'categories', 'comments',
'contactform', 'CSS', 'deleteaccount', 'demo', 'domains', 'downgrade', 'ecommerce',
'ecwid', 'email', 'export', 'followers', 'footer', 'formatting', 'frontpage',
'godaddy', 'header', 'i18n', 'import', 'io', 'IP', 'likes', 'links', 'mapping',
'media', 'menus', 'mobile', 'nomoreCSS', 'pages', 'podcast', 'presales', 'private',
'propagation', 'refund', 'sadday', 'security', 'SEO', 'settings', 'sharing', 'shopify',
'shoplocket', 'sites', 'spam', 'stats', 'tags', 'theme', 'TOS', 'trial', 'upgrades',
'uploads', 'users', 'video', 'wordads', 'widget', 'sayingno', 'alternative', 'wp1',
'wp2' ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment