forked from mourner/bullshit.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullshit.src.js
646 lines (597 loc) · 15.8 KB
/
bullshit.src.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
/*
Bullshit.js v0.1 (2013-01-11)
https://github.com/mourner/bullshit.js
(c) 2013 Vladimir Agafonkin, MIT License
*/
/**
* findAndReplaceDOMText v 0.2
* @author James Padolsey http://james.padolsey.com
* @license http://unlicense.org/UNLICENSE
*
* Matches the text of a DOM node against a regular expression
* and replaces each match (or node-separated portions of the match)
* in the specified element.
*
* Example: Wrap 'test' in <em>:
* <p id="target">This is a test</p>
* <script>
* findAndReplaceDOMText(
* /test/,
* document.getElementById('target'),
* 'em'
* );
* </script>
*/
window.findAndReplaceDOMText = (function() {
/**
* findAndReplaceDOMText
*
* Locates matches and replaces with replacementNode
*
* @param {RegExp} regex The regular expression to match
* @param {Node} node Element or Text node to search within
* @param {String|Element|Function} replacementNode A NodeName,
* Node to clone, or a function which returns a node to use
* as the replacement node.
* @param {Number} captureGroup A number specifiying which capture
* group to use in the match. (optional)
*/
function findAndReplaceDOMText(regex, node, replacementNode, captureGroup) {
var m, matches = [], text = _getText(node);
var replaceFn = _genReplacer(replacementNode);
if (!text) { return; }
if (regex.global) {
while (m = regex.exec(text)) {
matches.push(_getMatchIndexes(m, captureGroup));
}
} else {
m = text.match(regex);
matches.push(_getMatchIndexes(m, captureGroup));
}
if (matches.length) {
_stepThroughMatches(node, matches, replaceFn);
}
}
/**
* Gets the start and end indexes of a match
*/
function _getMatchIndexes(m, captureGroup) {
captureGroup = captureGroup || 0;
if (!m[0]) throw 'findAndReplaceDOMText cannot handle zero-length matches';
var index = m.index;
if (captureGroup > 0) {
var cg = m[captureGroup];
if (!cg) throw 'Invalid capture group';
index += m[0].indexOf(cg);
m[0] = cg;
}
return [ index, index + m[0].length, [ m[0] ] ];
};
/**
* Gets aggregate text of a node without resorting
* to broken innerText/textContent
*/
function _getText(node) {
if (node.nodeType === 3) {
return node.data;
}
var txt = '';
if (node = node.firstChild) do {
txt += _getText(node);
} while (node = node.nextSibling);
return txt;
}
/**
* Steps through the target node, looking for matches, and
* calling replaceFn when a match is found.
*/
function _stepThroughMatches(node, matches, replaceFn) {
var after, before,
startNode,
endNode,
startNodeIndex,
endNodeIndex,
innerNodes = [],
atIndex = 0,
curNode = node,
matchLocation = matches.shift(),
matchIndex = 0;
out: while (true) {
if (curNode.nodeType === 3) {
if (!endNode && curNode.length + atIndex >= matchLocation[1]) {
// We've found the ending
endNode = curNode;
endNodeIndex = matchLocation[1] - atIndex;
} else if (startNode) {
// Intersecting node
innerNodes.push(curNode);
}
if (!startNode && curNode.length + atIndex > matchLocation[0]) {
// We've found the match start
startNode = curNode;
startNodeIndex = matchLocation[0] - atIndex;
}
atIndex += curNode.length;
}
if (startNode && endNode) {
curNode = replaceFn({
startNode: startNode,
startNodeIndex: startNodeIndex,
endNode: endNode,
endNodeIndex: endNodeIndex,
innerNodes: innerNodes,
match: matchLocation[2],
matchIndex: matchIndex
});
// replaceFn has to return the node that replaced the endNode
// and then we step back so we can continue from the end of the
// match:
atIndex -= (endNode.length - endNodeIndex);
startNode = null;
endNode = null;
innerNodes = [];
matchLocation = matches.shift();
matchIndex++;
if (!matchLocation) {
break; // no more matches
}
} else if (curNode.firstChild || curNode.nextSibling) {
// Move down or forward:
curNode = curNode.firstChild || curNode.nextSibling;
continue;
}
// Move forward or up:
while (true) {
if (curNode.nextSibling) {
curNode = curNode.nextSibling;
break;
} else if (curNode.parentNode !== node) {
curNode = curNode.parentNode;
} else {
break out;
}
}
}
}
var reverts;
/**
* Reverts the last findAndReplaceDOMText process
*/
findAndReplaceDOMText.revert = function revert() {
for (var i = 0, l = reverts.length; i < l; ++i) {
reverts[i]();
}
reverts = [];
};
/**
* Generates the actual replaceFn which splits up text nodes
* and inserts the replacement element.
*/
function _genReplacer(nodeName) {
reverts = [];
var makeReplacementNode;
if (typeof nodeName != 'function') {
var stencilNode = nodeName.nodeType ? nodeName : document.createElement(nodeName);
makeReplacementNode = function(fill) {
var clone = document.createElement('div'),
el;
clone.innerHTML = stencilNode.outerHTML || new XMLSerializer().serializeToString(stencilNode);
el = clone.firstChild;
if (fill) {
el.appendChild(document.createTextNode(fill));
}
return el;
};
} else {
makeReplacementNode = nodeName;
}
return function replace(range) {
var startNode = range.startNode,
endNode = range.endNode,
matchIndex = range.matchIndex;
if (startNode === endNode) {
var node = startNode;
if (range.startNodeIndex > 0) {
// Add `before` text node (before the match)
var before = document.createTextNode(node.data.substring(0, range.startNodeIndex));
node.parentNode.insertBefore(before, node);
}
// Create the replacement node:
var el = makeReplacementNode(range.match[0], matchIndex);
node.parentNode.insertBefore(el, node);
if (range.endNodeIndex < node.length) {
// Add `after` text node (after the match)
var after = document.createTextNode(node.data.substring(range.endNodeIndex));
node.parentNode.insertBefore(after, node);
}
node.parentNode.removeChild(node);
reverts.push(function() {
var pnode = el.parentNode;
pnode.insertBefore(el.firstChild, el);
pnode.removeChild(el);
pnode.normalize();
});
return el;
} else {
// Replace startNode -> [innerNodes...] -> endNode (in that order)
var before = document.createTextNode(startNode.data.substring(0, range.startNodeIndex));
var after = document.createTextNode(endNode.data.substring(range.endNodeIndex));
var elA = makeReplacementNode(startNode.data.substring(range.startNodeIndex), matchIndex);
var innerEls = [];
for (var i = 0, l = range.innerNodes.length; i < l; ++i) {
var innerNode = range.innerNodes[i];
var innerEl = makeReplacementNode(innerNode.data, matchIndex);
innerNode.parentNode.replaceChild(innerEl, innerNode);
innerEls.push(innerEl);
}
var elB = makeReplacementNode(endNode.data.substring(0, range.endNodeIndex), matchIndex);
startNode.parentNode.insertBefore(before, startNode);
startNode.parentNode.insertBefore(elA, startNode);
startNode.parentNode.removeChild(startNode);
endNode.parentNode.insertBefore(elB, endNode);
endNode.parentNode.insertBefore(after, endNode);
endNode.parentNode.removeChild(endNode);
reverts.push(function() {
innerEls.unshift(elA);
innerEls.push(elB);
for (var i = 0, l = innerEls.length; i < l; ++i) {
var el = innerEls[i];
var pnode = el.parentNode;
pnode.insertBefore(el.firstChild, el);
pnode.removeChild(el);
pnode.normalize();
}
});
return elB;
}
};
}
return findAndReplaceDOMText;
}());
(function (window, undefined) {
var bullshitTerms = [
'(market|goal|community|quality|results|sales|user|customer' +
'|subject|role|service|client|process|business)' +
'.(centric(ity)?|facing|oriented|driven|focused|assessment|service)',
'24/7',
'a-b testing',
'accessib(le|ility)',
'acquisition',
'action items?',
'advantages?',
'aggregate',
'analytics?',
'application service providers?',
'assets?',
'authoritative',
'automated',
'b2b',
'back to the drawing board',
'ball.?park',
'band.aid',
'bandwidth',
'benchmark',
'(benefit|gap) analysis',
'best.of.breed',
'best.practice',
'big.data',
'big picture',
'bottom line',
'bottom.up',
'brain.?storm',
'brain.?dump',
'brand(s?|ing|ed)',
'burn.rates?',
'business.(cases|plans)?',
'buzz',
'call to action',
'capacity',
'capitalize',
'center of excellence',
'challenges?',
'change agent',
'circle the wagons',
'collaborat(e|ion)',
'communicat(e|ion)',
'compelling',
'competitive( advantage)?',
'connect the dots',
'content management',
'contingency plan',
'control group',
'convergent',
'conversion',
'core business',
'core competenc(y|ies)',
'cost-effective',
'cost/benefit',
'cost control',
'craftsmanship',
'critical path',
'crm',
'cross.sell',
'crowd.?(fund(s?|ed|ing)|sourc(ed|e|ing))',
'cutting.edge',
'data mining',
'deep dive',
'delight the customers?',
'deliverables?',
'demographic',
'discovery',
'diversity',
'downsize',
'drill down',
'drink the kool-aid',
'drop.?in',
'drop the ball',
'due dilligence',
'dynamic',
'e-?(business|commerce|tailers)',
'ecosystems?',
'efficien(t|cy)',
'elaboration',
'elephant in the room',
'elevator pitch',
'emerging markets',
'empower(ment)?',
'end of the day',
'end to end',
'engage',
'enhance',
'enterprise',
'eta',
'etched in stone',
'exceed expectations',
'expectations',
'experiences',
'experts?',
'expertise',
'exposure',
'eyeballs',
'facilitat(e|or)',
'fast track',
'fault.tolerant',
'first to market',
'flexibility',
'followup',
'foot view',
'front lines',
'functional',
'full benefit',
'game plan',
'go public',
'go to market',
'goals?',
'going forward',
'google juice',
'graceful.degradation',
'gradual.enhancement',
'granular',
'growth',
'grow',
'guidance',
'hardball',
'having said that',
'heads.up',
'heavy.lifting',
'herding cats',
'high.level',
'(high|mass).impact',
'impactful',
'impeccable',
'implementation',
'in a nutshell',
'incent',
'incentivize',
'increase the odds',
'innovat(e|ed|ion|ive|ing|or)',
'integrat(e|ed|ion)',
'internet of things',
'intellectual property',
'intuitive',
'knowledge base',
'knowledge transfer',
'landing pages?',
'lead the field',
'leadership',
'legacy',
'lessons learned',
'level playing field',
'level set',
'leverage',
'low-hanging fruit',
'look.(&|and).feel',
'market leader',
'market window',
'marketing collateral',
'maximize',
'measurement',
'methodolog(y|ies)',
'metrics',
'middleware',
'milestone',
'mind share',
'mind shower',
'mindset',
'mindshare',
'(mission|time).critical',
'monetize',
'moving forward',
'multitask(ing?)',
'negotiated',
'networking',
'new economy',
'next level',
'niches?',
'no-brainer',
'non-traditional management',
'objectives',
'occupy the field',
'off.site',
'off.the.(radar|shelf)',
'on board',
'on the (back end|radar screen|same page)',
'one to one',
'opportunit(y|ies)',
'(search engine )?optimization',
'optimal',
'out(side)?.of.the.(box|loop)',
'outsourc(e|ed|ing)',
'(total cost of )?ownership',
'paradigms?( shift)?',
'partner(ships?)?',
'patent',
'performance indicators',
'personalization',
'perspective',
'phase',
'phased approach',
'pipeline',
'planning horizon',
'plug.?in',
'prioritized?',
'proactive',
'problem space',
'processes',
'profit(ability)?',
'promotion',
'promotional collateral',
'prominent',
'proprietary',
'proof.of.concept',
'push the envelope',
'push.back',
'quick win',
'rais(e|ing) the bar',
'ramp.up',
'relationship management',
'responsive',
'engage(ments?)?',
'reach out',
'reactivation',
'real.time',
'real.world',
'reconfigure',
'red flag',
'reengineering',
'reinvent(ing)? the(.square)? wheel',
'reinvigorate',
'relevance',
'repurpose',
'resource allocation',
'restructuring',
'retention',
'return on investment',
'reus(e|ability)',
'revenue',
'reverse.engineer',
'revisit',
'road ?map',
'robust',
'roi',
'run the numbers',
'scale',
'scenarios?',
'scope',
'seamless',
'secret sauce',
'segment',
'self-managed team',
'seo',
'shareholder value',
'single-source responsibility',
'skill sets?',
'smoke (&|and) mirrors',
'social(.media|.gaming|.networks?)',
'solutions?',
'soup to nuts',
'sow',
'stakeholder',
'start.up?',
'statement of work',
'sticky-?ness',
'strateg(y|ic|ize)',
'streamline',
'success(ful)?',
'sustainab(le|ility)',
'synerg(y|ies)',
'tailwinds?',
'take offline',
'talking points',
'target (audience|group)',
'targeted',
'tasked',
'tco',
'team.building',
'team.player',
'teamwork',
'technologies',
'that being said',
'time.to.market',
'timelines?',
'top.down',
'top of the game',
'total quality',
'touch.base',
'touchpoints',
'traction',
'turnkey',
'up.to.speed',
'up-?sell',
'upside',
'user.friendly',
'user.experience',
'utiliz(e|ation)',
'unique approach',
'values?',
'value-added',
'vertical market',
'viral',
'virtual(ization)?',
'visibility',
'vision',
'walk the talk',
'web.enabled',
'win-win',
'wisdom of crowds',
'workflow',
'workshop',
'world.?class',
'wow.factor',
// technical bullshit
'cloud',
'(object|aspect).oriented',
'(framework|platform).agnostic',
'(front.?end.|ui.)?framework',
'html5',
'mv(c|p)',
'nosql',
'off-?line',
'oop',
'web (2|3)\\.0'
];
function revealBullshit(term) {
var c = term.charAt(0),
bullshit = (c === c.toUpperCase() ? 'B' : 'b') + 'ullshit',
last = term.length - 1;
if (term.substr(last - 2) === 'ing') {
bullshit += 'ting';
}
if (term.charAt(last - 1) !== 's' && term.charAt(last) === 's') {
bullshit += 's';
}
if (term.charAt(last - 2) !== 'e' && term.substr(last - 1) === 'ed') {
bullshit += 'ted';
}
if (term.charAt(last - 2) !== ('o' || 'e') && term.substr(last - 1) === ('or' || 'er')) {
bullshit += 'ter';
}
var abbr = document.createElement("abbr");
abbr.style.color = 'red';
abbr.title = term;
abbr.innerHTML = bullshit;
return abbr;
}
var bullshitRe = new RegExp('(' + bullshitTerms.join('|') + ')(?!\\w|[^<]*>)', 'gi');
findAndReplaceDOMText(bullshitRe, document.body, revealBullshit);
}(this));