Last active
August 29, 2017 15:26
-
-
Save adamthedeveloper/b53074fe175d5baa6cffbbbe822e3e4f to your computer and use it in GitHub Desktop.
Admin Links
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
// ==UserScript== | |
// @name Admin Opener | |
// @namespace https://www.givebrilliant.com | |
// @version 0.1 | |
// @description Open links found in the customer facing ideabook pages in admin (only works for products) | |
// @author Adam Medeiros @ Brilliant | |
// @match *://www.givebrilliant.com/ideabooks/* | |
// @match *://givebrilliant.com/ideabooks/* | |
// @match *://www.givebrilliant.com/projects/* | |
// @match *://givebrilliant.com/projects/* | |
// @match *://lvh.me:3000/ideabooks/* | |
// @match *://lvh.me:3000/projects/* | |
// @match *://www.brilliantbranded.com/ideabooks/* | |
// @match *://brilliantbranded.com/ideabooks/* | |
// @match *://www.brilliantbranded.com/projects/* | |
// @match *://brilliantbranded.com/projects/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var linkTo = function(text,path,options) { | |
var defaults = { | |
position: 'relative', | |
fontSize: '10px' | |
}; | |
Object.assign(defaults, options); | |
var html = '<a style="position: ' + defaults.position + '; left: 0; top: 0; '; | |
html += 'background-color: #df1f4f; color: white; font-weight: bold; '; | |
html += 'font-size: ' + defaults.fontSize + '; padding: 5px; display: inline-block;" float: left; href="'; | |
html += path; | |
html += '" target="_blank">'; | |
html += text; | |
html += '</a>'; | |
return html; | |
}; | |
var productLinks = $('div.product_photo a[href]').not('.love'); | |
$.each(productLinks, function(i, prodLink) { | |
var link = $(prodLink); | |
var adminPath = '/admin' + link.attr('href'); | |
var container = link.closest('div.product_photo'); | |
container.prepend(linkTo('OPEN IN ADA', adminPath, {position: 'absolute'})); | |
}); | |
var userElem = $('strong[data-ideabook-user]'); | |
if (userElem) { | |
var id = userElem.attr('data-ideabook-user'); | |
var par = userElem.parent(); | |
var textArray = par.text().split('by'); | |
var userName = textArray[textArray.length-1]; | |
var link = linkTo(userName, '/admin/users/' + id); | |
var newContents = ' ' + par.html().replace(userName, link); | |
par.html(newContents); | |
} | |
var heading = $('div.ideabook_description h2'); | |
heading.html(linkTo(heading.text() + ' (OPEN IN ADA)', '/admin' + location.pathname, {fontSize: 'inherit'})); | |
var estimateLinks = $('div#your_project button.submit a'); | |
$.each(estimateLinks, function(i, estLink) { | |
var link = $(estLink); | |
var adaLink = linkTo('OPEN IN ADA', '/admin' + link.attr('href'), {position: 'absolute'}); | |
var par = link.parent(); | |
par.append(adaLink); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment