Advertisement
bhtooefr

Seeking Alpha's "roadblock" script

Apr 15th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(w) {
  2.   var getParam = function (name) {
  3.     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  4.     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  5.         results = regex.exec(w.location.search);
  6.     return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  7.   },
  8.   rc = function(n) {
  9.     var c = document.cookie.match(new RegExp('(^|;)\\s*' + escape(n) + '=([^;\\s]*)'));
  10.     return (c ? unescape(c[2]) : null);
  11.   },
  12.   paginate = function () {
  13.     if (!w.aConf.pagination.singlePage) {
  14.       document.write('<style>' + '.sa-a #a-cont .p {display:none;} .sa-a #a-cont .p.p' + page + ' {display:block;}' + '</style>');
  15.     }
  16.   },
  17.   unblock_authors_pick = "false",
  18.   noRBCheck = function(){
  19.     return !!(log || fromPartner || fromInStream || !fromInsight || unblock_authors_pick === "true")
  20.   },
  21.   noRbStrategy = function () {
  22.     noRBandPagination = (noRBCheck() || pages === 1 );
  23.     w.aConf.pagination = {
  24.       limit: pLimit,
  25.       pages: pages,
  26.       page: page,
  27.       singlePage: noRBandPagination,
  28.       singlePageBtn: false
  29.     };
  30.  
  31.     w.aConf.roadblock = {
  32.       timed: false,
  33.       active: false,
  34.       type: 'no_rb_strategy'
  35.     };
  36.   },
  37.   softRbStrategy = function () {
  38.     var hideRb = noRBCheck();
  39.  
  40.     w.aConf.pagination = {
  41.       limit: 100,
  42.       pages: pages,
  43.       page: page,
  44.       singlePage: hideRb,
  45.       singlePageBtn: false
  46.     };
  47.  
  48.     w.aConf.roadblock = {
  49.       timed: !hideRb,
  50.       active: !hideRb,
  51.       type: 'soft_rb_strategy'
  52.     };
  53.   },
  54.   hardRbStrategy = function () {
  55.     firstArticle = parseInt(store.getItem('skipped_rb'), 10) === id;
  56.     noRBandPagination = (noRBCheck() || pages === 1 );
  57.     timedRBNotActive = noRBandPagination || (firstArticle && page === 1);
  58.     rbNotActive = noRBandPagination || page < pLimit;
  59.  
  60.     w.aConf.pagination = {
  61.       limit: pLimit,
  62.       pages: pages,
  63.       page: page,
  64.       singlePage: noRBandPagination,
  65.       singlePageBtn: false
  66.     };
  67.  
  68.     w.aConf.roadblock = {
  69.       timed: !timedRBNotActive,
  70.       active: !rbNotActive,
  71.       type: 'hard_rb_strategy'
  72.     };
  73.   };
  74.  
  75.   var pLimit = 2,
  76.     pages = 6,
  77.     log = rc('user_id'),
  78.     p = parseInt(getParam('page'), 10) || 1,
  79.     page = (p < 1) ? 1 : p,
  80.     id = 4162910,
  81.     source = rc('_sasource') || getParam('source') || '',
  82.     store = w.sessionStorage,
  83.     ls = w.localStorage,
  84.     fromPartner = (/cnbc|marketwatch|aoldf|msn|nasdaq|bloomberg|partner_djnw|partner_thomsonreuters/).test(source),
  85.     fromInStream = /instream/.test(source),
  86.     fromInsight = true;
  87.  
  88.   try {
  89.     if (!store.getItem('skipped_rb')) {
  90.       store.setItem('skipped_rb', id);
  91.     }
  92.   } catch (e) {
  93.     // do nothing
  94.   }
  95.  
  96.   if (pages === 2) {
  97.     pages = 3;
  98.   }
  99.  
  100.   w.aConf = {};
  101.   var firstArticle,
  102.     noRBandPagination,
  103.     timedRBNotActive,
  104.     rbNotActive,
  105.     rbType = (ls.getItem('roadblock_calc_type') || 'no_rb_strategy').trim();
  106.  
  107.   switch (rbType) {
  108.     case 'no_rb_strategy':
  109.     case 'control':
  110.       noRbStrategy();
  111.       break;
  112.     case 'soft_rb_strategy':
  113.       softRbStrategy();
  114.       break;
  115.     case 'hard_rb_strategy':
  116.       hardRbStrategy();
  117.       break;
  118.     default:
  119.       noRbStrategy();
  120.       break;
  121.   }
  122.  
  123.   paginate();
  124.  
  125. }(window));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement