Skip to content

Instantly share code, notes, and snippets.

@trialforce
Last active December 15, 2016 13:45
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 trialforce/aa05c91f4be33aaef62f6c9fb01cd26d to your computer and use it in GitHub Desktop.
Save trialforce/aa05c91f4be33aaef62f6c9fb01cd26d to your computer and use it in GitHub Desktop.
<div id="serp"></div>
<div id="serp2"></div>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
function createSerp(id)
{
$('#' + id).html(
'<div style="width: 651px; height: 91px; font-family: arial, sans-serif; border: solid 1px #eee; padding: 6px 14px; box-sizing: border-box; overflow:">' +
'<h3 style="margin:0;">' +
' <a class="serp-title" href="#"' +
' style="color: #1a0dab;font-size: 18px; text-decoration: none; font-weight: normal; height: 23px; overflow: hidden; display: inline-block;"' +
' target="_BLANK">' +
' </a>' +
'</h3>' +
'<div>' +
' <cite class="serp-url"' +
' style="color:#006621;font-style: normal;font-size: 14px; display: inline-block;height: 14px;">' +
' </cite>' +
' <br/>' +
' <span class="serp-text"' +
' style="color: #545454; line-height: 1.4; word-wrap: break-word;font-size: 13px; display: inline-block; height: 34px; overflow: hidden;">' +
' </span>' +
'</div>' +
'</div>');
}
function setSerp(id, title, url, text)
{
var originalUrl = url;
title = title.substring(0, 70);
url = url.substring(0, 80).replace('http://', '').replace('https://', '').replace('ftp://', '');
text = text.replace(/(<([^>]+)>)/ig, "").substring(0, 210);
$('#' + id + ' .serp-title').attr('href', originalUrl);
$('#' + id + ' .serp-title').html(title);
$('#' + id + ' .serp-url').html(url);
$('#' + id + ' .serp-text').html(text);
}
createSerp('serp');
setSerp('serp',
'Page title is limited into 70 characters',
'https://www.google.com',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.');
createSerp('serp2');
setSerp('serp2',
'This is a second serp',
'https://www.google.com.br',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment